mutex.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. ** $Id: mutex.h,v 1.2 2007/08/30 14:10:30 drh Exp $
  23. */
  24. #ifdef SQLITE_MUTEX_APPDEF
  25. /*
  26. ** If SQLITE_MUTEX_APPDEF is defined, then this whole module is
  27. ** omitted and equivalent functionality must be provided by the
  28. ** application that links against the SQLite library.
  29. */
  30. #else
  31. /*
  32. ** Figure out what version of the code to use. The choices are
  33. **
  34. ** SQLITE_MUTEX_NOOP For single-threaded applications that
  35. ** do not desire error checking.
  36. **
  37. ** SQLITE_MUTEX_NOOP_DEBUG For single-threaded applications with
  38. ** error checking to help verify that mutexes
  39. ** are being used correctly even though they
  40. ** are not needed. Used when SQLITE_DEBUG is
  41. ** defined on single-threaded builds.
  42. **
  43. ** SQLITE_MUTEX_PTHREADS For multi-threaded applications on Unix.
  44. **
  45. ** SQLITE_MUTEX_W32 For multi-threaded applications on Win32.
  46. **
  47. ** SQLITE_MUTEX_OS2 For multi-threaded applications on OS/2.
  48. */
  49. #define SQLITE_MUTEX_NOOP 1 /* The default */
  50. #if defined(SQLITE_DEBUG) && !SQLITE_THREADSAFE
  51. # undef SQLITE_MUTEX_NOOP
  52. # define SQLITE_MUTEX_NOOP_DEBUG
  53. #endif
  54. #if defined(SQLITE_MUTEX_NOOP) && SQLITE_THREADSAFE && OS_UNIX
  55. # undef SQLITE_MUTEX_NOOP
  56. # define SQLITE_MUTEX_PTHREADS
  57. #endif
  58. #if defined(SQLITE_MUTEX_NOOP) && SQLITE_THREADSAFE && OS_WIN
  59. # undef SQLITE_MUTEX_NOOP
  60. # define SQLITE_MUTEX_W32
  61. #endif
  62. #if defined(SQLITE_MUTEX_NOOP) && SQLITE_THREADSAFE && OS_OS2
  63. # undef SQLITE_MUTEX_NOOP
  64. # define SQLITE_MUTEX_OS2
  65. #endif
  66. #ifdef SQLITE_MUTEX_NOOP
  67. /*
  68. ** If this is a no-op implementation, implement everything as macros.
  69. */
  70. #define sqlite3_mutex_alloc(X) ((sqlite3_mutex*)8)
  71. #define sqlite3_mutex_free(X)
  72. #define sqlite3_mutex_enter(X)
  73. #define sqlite3_mutex_try(X) SQLITE_OK
  74. #define sqlite3_mutex_leave(X)
  75. #define sqlite3_mutex_held(X) 1
  76. #define sqlite3_mutex_notheld(X) 1
  77. #endif
  78. #endif /* SQLITE_MUTEX_APPDEF */