os0sync.ic
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:1k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /******************************************************
  2. The interface to the operating system synchronization primitives.
  3. (c) 1995 Innobase Oy
  4. Created 9/6/1995 Heikki Tuuri
  5. *******************************************************/
  6. #ifdef __WIN__
  7. #include <winbase.h>
  8. #endif
  9. #ifndef _WIN32
  10. /**************************************************************
  11. Acquires ownership of a fast mutex. */
  12. UNIV_INLINE
  13. ulint
  14. os_fast_mutex_trylock(
  15. /*==================*/
  16. /* out: 0 if success, != 0 if
  17. was reserved by another
  18. thread */
  19. os_fast_mutex_t* fast_mutex) /* in: mutex to acquire */
  20. {
  21. #ifdef __WIN__
  22. int ret;
  23. /* TODO: TryEnterCriticalSection is probably not found from
  24. NT versions < 4! */
  25. ret = TryEnterCriticalSection(fast_mutex);
  26. if (ret) {
  27. return(0);
  28. }
  29. return(1);
  30. #else
  31. return((ulint) pthread_mutex_trylock(fast_mutex));
  32. #endif
  33. }
  34. /**************************************************************
  35. Releases ownership of a fast mutex. */
  36. UNIV_INLINE
  37. void
  38. os_fast_mutex_unlock(
  39. /*=================*/
  40. os_fast_mutex_t* fast_mutex) /* in: mutex to release */
  41. {
  42. #ifdef __WIN__
  43. LeaveCriticalSection(fast_mutex);
  44. #else
  45. pthread_mutex_unlock(fast_mutex);
  46. #endif
  47. }
  48. #endif