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