00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef _DB_MUTEX_H_
00011 #define _DB_MUTEX_H_
00012
00013
00014
00015
00016
00017
00018 #define MUTEX_INVALID 0
00019
00020
00021
00022
00023 #define MTX_APPLICATION 1
00024 #define MTX_DB_HANDLE 2
00025 #define MTX_ENV_DBLIST 3
00026 #define MTX_ENV_REGION 4
00027 #define MTX_LOCK_REGION 5
00028 #define MTX_LOGICAL_LOCK 6
00029 #define MTX_LOG_FILENAME 7
00030 #define MTX_LOG_FLUSH 8
00031 #define MTX_LOG_HANDLE 9
00032 #define MTX_LOG_REGION 10
00033 #define MTX_MPOOLFILE_HANDLE 11
00034 #define MTX_MPOOL_BUFFER 12
00035 #define MTX_MPOOL_FH 13
00036 #define MTX_MPOOL_HANDLE 14
00037 #define MTX_MPOOL_HASH_BUCKET 15
00038 #define MTX_MPOOL_REGION 16
00039 #define MTX_MUTEX_REGION 17
00040 #define MTX_MUTEX_TEST 18
00041 #define MTX_REP_DATABASE 19
00042 #define MTX_REP_REGION 20
00043 #define MTX_SEQUENCE 21
00044 #define MTX_TWISTER 22
00045 #define MTX_TXN_ACTIVE 23
00046 #define MTX_TXN_CHKPT 24
00047 #define MTX_TXN_COMMIT 25
00048 #define MTX_TXN_REGION 26
00049 #define MTX_MAX_ENTRY 26
00050
00051
00052 #if defined(HAVE_MUTEX_PTHREADS) || \
00053 defined(HAVE_MUTEX_SOLARIS_LWP) || \
00054 defined(HAVE_MUTEX_UI_THREADS)
00055 #define __mutex_init(a, b, c) __db_pthread_mutex_init(a, b, c)
00056 #define __mutex_lock(a, b) __db_pthread_mutex_lock(a, b)
00057 #define __mutex_unlock(a, b) __db_pthread_mutex_unlock(a, b)
00058 #define __mutex_destroy(a, b) __db_pthread_mutex_destroy(a, b)
00059 #endif
00060
00061 #if defined(HAVE_MUTEX_WIN32) || defined(HAVE_MUTEX_WIN32_GCC)
00062 #define __mutex_init(a, b, c) __db_win32_mutex_init(a, b, c)
00063 #define __mutex_lock(a, b) __db_win32_mutex_lock(a, b)
00064 #define __mutex_unlock(a, b) __db_win32_mutex_unlock(a, b)
00065 #define __mutex_destroy(a, b) __db_win32_mutex_destroy(a, b)
00066 #endif
00067
00068 #if defined(HAVE_MUTEX_FCNTL)
00069 #define __mutex_init(a, b, c) __db_fcntl_mutex_init(a, b, c)
00070 #define __mutex_lock(a, b) __db_fcntl_mutex_lock(a, b)
00071 #define __mutex_unlock(a, b) __db_fcntl_mutex_unlock(a, b)
00072 #define __mutex_destroy(a, b) __db_fcntl_mutex_destroy(a, b)
00073 #endif
00074
00075 #ifndef __mutex_init
00076 #define __mutex_init(a, b, c) __db_tas_mutex_init(a, b, c)
00077 #define __mutex_lock(a, b) __db_tas_mutex_lock(a, b)
00078 #define __mutex_unlock(a, b) __db_tas_mutex_unlock(a, b)
00079 #define __mutex_destroy(a, b) __db_tas_mutex_destroy(a, b)
00080 #endif
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 #define MUTEX_LOCK(dbenv, mutex) do { \
00091 if ((mutex) != MUTEX_INVALID && \
00092 __mutex_lock(dbenv, mutex) != 0) \
00093 return (DB_RUNRECOVERY); \
00094 } while (0)
00095 #define MUTEX_UNLOCK(dbenv, mutex) do { \
00096 if ((mutex) != MUTEX_INVALID && \
00097 __mutex_unlock(dbenv, mutex) != 0) \
00098 return (DB_RUNRECOVERY); \
00099 } while (0)
00100
00101
00102
00103
00104 #ifdef HAVE_MUTEX_VXWORKS
00105 #include "taskLib.h"
00106
00107
00108
00109
00110 #define DB_BEGIN_SINGLE_THREAD do { \
00111 if (DB_GLOBAL(db_global_init)) \
00112 (void)semTake(DB_GLOBAL(db_global_lock), WAIT_FOREVER); \
00113 else { \
00114 taskLock(); \
00115 if (DB_GLOBAL(db_global_init)) { \
00116 taskUnlock(); \
00117 (void)semTake(DB_GLOBAL(db_global_lock), \
00118 WAIT_FOREVER); \
00119 continue; \
00120 } \
00121 DB_GLOBAL(db_global_lock) = \
00122 semBCreate(SEM_Q_FIFO, SEM_EMPTY); \
00123 if (DB_GLOBAL(db_global_lock) != NULL) \
00124 DB_GLOBAL(db_global_init) = 1; \
00125 taskUnlock(); \
00126 } \
00127 } while (DB_GLOBAL(db_global_init) == 0)
00128 #define DB_END_SINGLE_THREAD (void)semGive(DB_GLOBAL(db_global_lock))
00129 #endif
00130
00131
00132
00133
00134 #ifndef DB_BEGIN_SINGLE_THREAD
00135 #define DB_BEGIN_SINGLE_THREAD
00136 #endif
00137 #ifndef DB_END_SINGLE_THREAD
00138 #define DB_END_SINGLE_THREAD
00139 #endif
00140
00141 #include "dbinc_auto/mutex_ext.h"
00142 #endif