drh | 437b901 | 2007-08-28 16:34:42 +0000 | [diff] [blame] | 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. |
drh | 437b901 | 2007-08-28 16:34:42 +0000 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | |
drh | 437b901 | 2007-08-28 16:34:42 +0000 | [diff] [blame] | 24 | /* |
| 25 | ** Figure out what version of the code to use. The choices are |
| 26 | ** |
drh | 18472fa | 2008-10-07 15:25:48 +0000 | [diff] [blame] | 27 | ** SQLITE_MUTEX_OMIT No mutex logic. Not even stubs. The |
peter.d.reid | 60ec914 | 2014-09-06 16:39:46 +0000 | [diff] [blame] | 28 | ** mutexes implementation cannot be overridden |
drh | 18472fa | 2008-10-07 15:25:48 +0000 | [diff] [blame] | 29 | ** at start-time. |
drh | 437b901 | 2007-08-28 16:34:42 +0000 | [diff] [blame] | 30 | ** |
drh | 18472fa | 2008-10-07 15:25:48 +0000 | [diff] [blame] | 31 | ** SQLITE_MUTEX_NOOP For single-threaded applications. No |
| 32 | ** mutual exclusion is provided. But this |
| 33 | ** implementation can be overridden at |
| 34 | ** start-time. |
drh | 437b901 | 2007-08-28 16:34:42 +0000 | [diff] [blame] | 35 | ** |
| 36 | ** SQLITE_MUTEX_PTHREADS For multi-threaded applications on Unix. |
| 37 | ** |
drh | c7ce76a | 2007-08-30 14:10:30 +0000 | [diff] [blame] | 38 | ** SQLITE_MUTEX_W32 For multi-threaded applications on Win32. |
drh | 437b901 | 2007-08-28 16:34:42 +0000 | [diff] [blame] | 39 | */ |
drh | 18472fa | 2008-10-07 15:25:48 +0000 | [diff] [blame] | 40 | #if !SQLITE_THREADSAFE |
| 41 | # define SQLITE_MUTEX_OMIT |
drh | 437b901 | 2007-08-28 16:34:42 +0000 | [diff] [blame] | 42 | #endif |
drh | 18472fa | 2008-10-07 15:25:48 +0000 | [diff] [blame] | 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 |
drh | 18472fa | 2008-10-07 15:25:48 +0000 | [diff] [blame] | 48 | # else |
| 49 | # define SQLITE_MUTEX_NOOP |
| 50 | # endif |
drh | 437b901 | 2007-08-28 16:34:42 +0000 | [diff] [blame] | 51 | #endif |
| 52 | |
drh | 18472fa | 2008-10-07 15:25:48 +0000 | [diff] [blame] | 53 | #ifdef SQLITE_MUTEX_OMIT |
drh | 437b901 | 2007-08-28 16:34:42 +0000 | [diff] [blame] | 54 | /* |
| 55 | ** If this is a no-op implementation, implement everything as macros. |
| 56 | */ |
| 57 | #define sqlite3_mutex_alloc(X) ((sqlite3_mutex*)8) |
| 58 | #define sqlite3_mutex_free(X) |
drh | 30ddce6 | 2011-10-15 00:16:30 +0000 | [diff] [blame] | 59 | #define sqlite3_mutex_enter(X) |
drh | 437b901 | 2007-08-28 16:34:42 +0000 | [diff] [blame] | 60 | #define sqlite3_mutex_try(X) SQLITE_OK |
drh | 30ddce6 | 2011-10-15 00:16:30 +0000 | [diff] [blame] | 61 | #define sqlite3_mutex_leave(X) |
shaneh | bd2aaf9 | 2010-09-01 02:38:21 +0000 | [diff] [blame] | 62 | #define sqlite3_mutex_held(X) ((void)(X),1) |
| 63 | #define sqlite3_mutex_notheld(X) ((void)(X),1) |
drh | 8c4d6b9 | 2008-06-19 01:50:09 +0000 | [diff] [blame] | 64 | #define sqlite3MutexAlloc(X) ((sqlite3_mutex*)8) |
danielk1977 | d025174 | 2008-06-18 18:57:42 +0000 | [diff] [blame] | 65 | #define sqlite3MutexInit() SQLITE_OK |
| 66 | #define sqlite3MutexEnd() |
drh | 30ddce6 | 2011-10-15 00:16:30 +0000 | [diff] [blame] | 67 | #define MUTEX_LOGIC(X) |
| 68 | #else |
| 69 | #define MUTEX_LOGIC(X) X |
dan | 1cf021e | 2009-09-30 04:28:04 +0000 | [diff] [blame] | 70 | #endif /* defined(SQLITE_MUTEX_OMIT) */ |