xref: /sqlite-3.40.0/src/mutex.h (revision e2b7a769)
1437b9013Sdrh /*
2437b9013Sdrh ** 2007 August 28
3437b9013Sdrh **
4437b9013Sdrh ** The author disclaims copyright to this source code.  In place of
5437b9013Sdrh ** a legal notice, here is a blessing:
6437b9013Sdrh **
7437b9013Sdrh **    May you do good and not evil.
8437b9013Sdrh **    May you find forgiveness for yourself and forgive others.
9437b9013Sdrh **    May you share freely, never taking more than you give.
10437b9013Sdrh **
11437b9013Sdrh *************************************************************************
12437b9013Sdrh **
13437b9013Sdrh ** This file contains the common header for all mutex implementations.
14437b9013Sdrh ** The sqliteInt.h header #includes this file so that it is available
15437b9013Sdrh ** to all source files.  We break it out in an effort to keep the code
16437b9013Sdrh ** better organized.
17437b9013Sdrh **
18437b9013Sdrh ** NOTE:  source files should *not* #include this header file directly.
19437b9013Sdrh ** Source files should #include the sqliteInt.h file and let that file
20437b9013Sdrh ** include this one indirectly.
21437b9013Sdrh */
22437b9013Sdrh 
23437b9013Sdrh 
24437b9013Sdrh /*
25437b9013Sdrh ** Figure out what version of the code to use.  The choices are
26437b9013Sdrh **
2718472fa7Sdrh **   SQLITE_MUTEX_OMIT         No mutex logic.  Not even stubs.  The
2860ec914cSpeter.d.reid **                             mutexes implementation cannot be overridden
2918472fa7Sdrh **                             at start-time.
30437b9013Sdrh **
3118472fa7Sdrh **   SQLITE_MUTEX_NOOP         For single-threaded applications.  No
3218472fa7Sdrh **                             mutual exclusion is provided.  But this
3318472fa7Sdrh **                             implementation can be overridden at
3418472fa7Sdrh **                             start-time.
35437b9013Sdrh **
36437b9013Sdrh **   SQLITE_MUTEX_PTHREADS     For multi-threaded applications on Unix.
37437b9013Sdrh **
38c7ce76afSdrh **   SQLITE_MUTEX_W32          For multi-threaded applications on Win32.
39437b9013Sdrh */
4018472fa7Sdrh #if !SQLITE_THREADSAFE
4118472fa7Sdrh # define SQLITE_MUTEX_OMIT
42437b9013Sdrh #endif
4318472fa7Sdrh #if SQLITE_THREADSAFE && !defined(SQLITE_MUTEX_NOOP)
4418472fa7Sdrh #  if SQLITE_OS_UNIX
45437b9013Sdrh #    define SQLITE_MUTEX_PTHREADS
4618472fa7Sdrh #  elif SQLITE_OS_WIN
47c7ce76afSdrh #    define SQLITE_MUTEX_W32
4818472fa7Sdrh #  else
4918472fa7Sdrh #    define SQLITE_MUTEX_NOOP
5018472fa7Sdrh #  endif
51437b9013Sdrh #endif
52437b9013Sdrh 
5318472fa7Sdrh #ifdef SQLITE_MUTEX_OMIT
54437b9013Sdrh /*
55437b9013Sdrh ** If this is a no-op implementation, implement everything as macros.
56437b9013Sdrh */
57437b9013Sdrh #define sqlite3_mutex_alloc(X)    ((sqlite3_mutex*)8)
58437b9013Sdrh #define sqlite3_mutex_free(X)
59437b9013Sdrh #define sqlite3_mutex_enter(X)
60437b9013Sdrh #define sqlite3_mutex_try(X)      SQLITE_OK
61437b9013Sdrh #define sqlite3_mutex_leave(X)
62bd2aaf9aSshaneh #define sqlite3_mutex_held(X)     ((void)(X),1)
63bd2aaf9aSshaneh #define sqlite3_mutex_notheld(X)  ((void)(X),1)
648c4d6b97Sdrh #define sqlite3MutexAlloc(X)      ((sqlite3_mutex*)8)
65d025174fSdanielk1977 #define sqlite3MutexInit()        SQLITE_OK
66d025174fSdanielk1977 #define sqlite3MutexEnd()
6730ddce6fSdrh #define MUTEX_LOGIC(X)
6830ddce6fSdrh #else
6930ddce6fSdrh #define MUTEX_LOGIC(X)            X
70*e2b7a769Sdrh int sqlite3_mutex_held(sqlite3_mutex*);
711cf021e1Sdan #endif /* defined(SQLITE_MUTEX_OMIT) */
72