1
0

mutex.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. ** 2007 August 28
  3. **
  4. ** The author disclaims copyright to this source code. In place of
  5. ** a legal notice, here is a blessing:
  6. **
  7. ** May you do good and not evil.
  8. ** May you find forgiveness for yourself and forgive others.
  9. ** May you share freely, never taking more than you give.
  10. **
  11. *************************************************************************
  12. **
  13. ** This file contains the common header for all mutex implementations.
  14. ** The sqliteInt.h header #includes this file so that it is available
  15. ** to all source files. We break it out in an effort to keep the code
  16. ** better organized.
  17. **
  18. ** NOTE: source files should *not* #include this header file directly.
  19. ** Source files should #include the sqliteInt.h file and let that file
  20. ** include this one indirectly.
  21. */
  22. /*
  23. ** Figure out what version of the code to use. The choices are
  24. **
  25. ** SQLITE_MUTEX_OMIT No mutex logic. Not even stubs. The
  26. ** mutexes implemention cannot be overridden
  27. ** at start-time.
  28. **
  29. ** SQLITE_MUTEX_NOOP For single-threaded applications. No
  30. ** mutual exclusion is provided. But this
  31. ** implementation can be overridden at
  32. ** start-time.
  33. **
  34. ** SQLITE_MUTEX_RTTHREAD For multi-threaded applications on rt-thread.
  35. **
  36. ** SQLITE_MUTEX_PTHREADS For multi-threaded applications on Unix.
  37. **
  38. ** SQLITE_MUTEX_W32 For multi-threaded applications on Win32.
  39. */
  40. #if !SQLITE_THREADSAFE
  41. # define SQLITE_MUTEX_OMIT
  42. #endif
  43. #if SQLITE_THREADSAFE && !defined(SQLITE_MUTEX_NOOP)
  44. # if SQLITE_OS_UNIX
  45. # define SQLITE_MUTEX_PTHREADS
  46. # elif SQLITE_OS_WIN
  47. # define SQLITE_MUTEX_W32
  48. # elif SQLITE_OS_RTTHREAD
  49. # define SQLITE_MUTEX_RTTHREAD
  50. # else
  51. # define SQLITE_MUTEX_NOOP
  52. # endif
  53. #endif
  54. #ifdef SQLITE_MUTEX_OMIT
  55. /*
  56. ** If this is a no-op implementation, implement everything as macros.
  57. */
  58. #define sqlite3_mutex_alloc(X) ((sqlite3_mutex*)8)
  59. #define sqlite3_mutex_free(X)
  60. #define sqlite3_mutex_enter(X)
  61. #define sqlite3_mutex_try(X) SQLITE_OK
  62. #define sqlite3_mutex_leave(X)
  63. #define sqlite3_mutex_held(X) ((void)(X),1)
  64. #define sqlite3_mutex_notheld(X) ((void)(X),1)
  65. #define sqlite3MutexAlloc(X) ((sqlite3_mutex*)8)
  66. #define sqlite3MutexInit() SQLITE_OK
  67. #define sqlite3MutexEnd()
  68. #define MUTEX_LOGIC(X)
  69. #else
  70. #define MUTEX_LOGIC(X) X
  71. #endif /* defined(SQLITE_MUTEX_OMIT) */