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