00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #define DB_BEGIN_SINGLE_THREAD
00011 #define DB_END_SINGLE_THREAD
00012
00013
00014
00015
00016 #ifdef HAVE_MUTEX_PTHREADS
00017 #include <pthread.h>
00018
00019 #define MUTEX_FIELDS \
00020 pthread_mutex_t mutex; \
00021 pthread_cond_t cond;
00022 #endif
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifdef HAVE_MUTEX_SOLARIS_LWP
00042
00043
00044
00045
00046
00047
00048 #include <synch.h>
00049
00050 #define MUTEX_FIELDS \
00051 lwp_mutex_t mutex; \
00052 lwp_cond_t cond;
00053 #endif
00054
00055
00056
00057
00058 #ifdef HAVE_MUTEX_UI_THREADS
00059 #include <thread.h>
00060 #include <synch.h>
00061
00062 #define MUTEX_FIELDS \
00063 mutex_t mutex; \
00064 cond_t cond;
00065 #endif
00066
00067
00068
00069
00070 #ifdef HAVE_MUTEX_AIX_CHECK_LOCK
00071 #include <sys/atomic_op.h>
00072 typedef int tsl_t;
00073
00074 #define MUTEX_INIT(x) 0
00075 #define MUTEX_ALIGN sizeof(int)
00076 #define MUTEX_SET(x) (!_check_lock(x, 0, 1))
00077 #define MUTEX_UNSET(x) _clear_lock(x, 0)
00078 #endif
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 #ifdef HAVE_MUTEX_HPPA_MSEM_INIT
00095 #define MUTEX_NO_MALLOC_LOCKS
00096 #define MUTEX_NO_SHMGET_LOCKS
00097
00098 #define MUTEX_ALIGN 16
00099 #endif
00100
00101 #if defined(HAVE_MUTEX_MSEM_INIT) || defined(HAVE_MUTEX_HPPA_MSEM_INIT)
00102 #include <sys/mman.h>
00103 typedef msemaphore tsl_t;
00104
00105 #ifndef MUTEX_ALIGN
00106 #define MUTEX_ALIGN sizeof(int)
00107 #endif
00108 #define MUTEX_INIT(x) (msem_init(x, MSEM_UNLOCKED) <= (msemaphore *)0)
00109 #define MUTEX_SET(x) (!msem_lock(x, MSEM_IF_NOWAIT))
00110 #define MUTEX_UNSET(x) msem_unlock(x, 0)
00111 #endif
00112
00113
00114
00115
00116
00117
00118
00119
00120 #ifdef HAVE_MUTEX_MACOS
00121 typedef unsigned char tsl_t;
00122
00123 #define MUTEX_INIT(x) 0
00124 #endif
00125
00126
00127
00128
00129 #ifdef HAVE_MUTEX_RELIANTUNIX_INITSPIN
00130 #include <ulocks.h>
00131 typedef spinlock_t tsl_t;
00132
00133 #define MUTEX_INIT(x) (initspin(x, 1), 0)
00134 #define MUTEX_SET(x) (cspinlock(x) == 0)
00135 #define MUTEX_UNSET(x) spinunlock(x)
00136 #endif
00137
00138
00139
00140
00141
00142
00143
00144
00145 #ifdef HAVE_MUTEX_SEMA_INIT
00146 #include <synch.h>
00147 typedef sema_t tsl_t;
00148
00149 #define MUTEX_ALIGN sizeof(int)
00150 #define MUTEX_INIT(x) (sema_init(x, 1, USYNC_PROCESS, NULL) != 0)
00151 #define MUTEX_SET(x) (sema_wait(x) == 0)
00152 #define MUTEX_UNSET(x) sema_post(x)
00153 #endif
00154
00155
00156
00157
00158 #ifdef HAVE_MUTEX_SGI_INIT_LOCK
00159 #include <abi_mutex.h>
00160 typedef abilock_t tsl_t;
00161
00162 #define MUTEX_ALIGN sizeof(int)
00163 #define MUTEX_INIT(x) (init_lock(x) != 0)
00164 #define MUTEX_SET(x) (!acquire_lock(x))
00165 #define MUTEX_UNSET(x) release_lock(x)
00166 #endif
00167
00168
00169
00170
00171
00172
00173
00174
00175 #ifdef HAVE_MUTEX_SOLARIS_LOCK_TRY
00176 #include <sys/machlock.h>
00177 typedef lock_t tsl_t;
00178
00179 #define MUTEX_ALIGN sizeof(int)
00180 #define MUTEX_INIT(x) 0
00181 #define MUTEX_SET(x) _lock_try(x)
00182 #define MUTEX_UNSET(x) _lock_clear(x)
00183 #endif
00184
00185
00186
00187
00188 #ifdef HAVE_MUTEX_VMS
00189 #include <sys/mman.h>;
00190 #include <builtins.h>
00191 typedef unsigned char tsl_t;
00192
00193 #define MUTEX_ALIGN sizeof(unsigned int)
00194 #ifdef __ALPHA
00195 #define MUTEX_SET(tsl) (!__TESTBITSSI(tsl, 0))
00196 #else
00197 #define MUTEX_SET(tsl) (!(int)_BBSSI(0, tsl))
00198 #endif
00199 #define MUTEX_UNSET(tsl) (*(tsl) = 0)
00200 #define MUTEX_INIT(tsl) MUTEX_UNSET(tsl)
00201 #endif
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211 #ifdef HAVE_MUTEX_VXWORKS
00212 #include "semLib.h"
00213 typedef SEM_ID tsl_t;
00214
00215 #define MUTEX_ALIGN sizeof(unsigned int)
00216 #define MUTEX_SET(tsl) (semTake((*tsl), WAIT_FOREVER) == OK)
00217 #define MUTEX_UNSET(tsl) (semGive((*tsl)) == OK)
00218 #define MUTEX_INIT(tsl) \
00219 ((*(tsl) = semBCreate(SEM_Q_FIFO, SEM_FULL)) == NULL)
00220
00221 #undef DB_BEGIN_SINGLE_THREAD
00222
00223
00224
00225
00226 #define DB_BEGIN_SINGLE_THREAD \
00227 do { \
00228 if (DB_GLOBAL(db_global_init)) \
00229 (void)semTake(DB_GLOBAL(db_global_lock), WAIT_FOREVER); \
00230 else { \
00231 taskLock(); \
00232 if (DB_GLOBAL(db_global_init)) { \
00233 taskUnlock(); \
00234 (void)semTake(DB_GLOBAL(db_global_lock), \
00235 WAIT_FOREVER); \
00236 continue; \
00237 } \
00238 DB_GLOBAL(db_global_lock) = \
00239 semBCreate(SEM_Q_FIFO, SEM_EMPTY); \
00240 if (DB_GLOBAL(db_global_lock) != NULL) \
00241 DB_GLOBAL(db_global_init) = 1; \
00242 taskUnlock(); \
00243 } \
00244 } while (DB_GLOBAL(db_global_init) == 0)
00245 #undef DB_END_SINGLE_THREAD
00246 #define DB_END_SINGLE_THREAD (void)semGive(DB_GLOBAL(db_global_lock))
00247 #endif
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258 #ifdef HAVE_MUTEX_WIN16
00259 typedef unsigned int tsl_t;
00260
00261 #define MUTEX_ALIGN sizeof(unsigned int)
00262 #define MUTEX_INIT(x) 0
00263 #define MUTEX_SET(tsl) (*(tsl) = 1)
00264 #define MUTEX_UNSET(tsl) (*(tsl) = 0)
00265 #endif
00266
00267
00268
00269
00270 #ifdef HAVE_MUTEX_WIN32
00271 typedef unsigned int tsl_t;
00272
00273 #define MUTEX_ALIGN sizeof(unsigned int)
00274 #define MUTEX_INIT(x) 0
00275 #define MUTEX_SET(tsl) (!InterlockedExchange((PLONG)tsl, 1))
00276 #define MUTEX_UNSET(tsl) (*(tsl) = 0)
00277 #endif
00278
00279
00280
00281
00282 #ifdef HAVE_MUTEX_68K_GCC_ASSEMBLY
00283 typedef unsigned char tsl_t;
00284 #endif
00285
00286
00287
00288
00289 #ifdef HAVE_MUTEX_ALPHA_GCC_ASSEMBLY
00290 typedef u_int32_t tsl_t;
00291
00292 #define MUTEX_ALIGN 4
00293 #endif
00294
00295
00296
00297
00298 #ifdef HAVE_MUTEX_HPPA_GCC_ASSEMBLY
00299 typedef u_int32_t tsl_t;
00300
00301 #define MUTEX_ALIGN 16
00302 #endif
00303
00304
00305
00306
00307 #ifdef HAVE_MUTEX_IA64_GCC_ASSEMBLY
00308 typedef unsigned char tsl_t;
00309 #endif
00310
00311
00312
00313
00314 #ifdef HAVE_MUTEX_SCO_X86_CC_ASSEMBLY
00315 typedef unsigned char tsl_t;
00316 #endif
00317
00318
00319
00320
00321 #ifdef HAVE_MUTEX_SPARC_GCC_ASSEMBLY
00322 typedef unsigned char tsl_t;
00323 #endif
00324
00325
00326
00327
00328 #ifdef HAVE_MUTEX_UTS_CC_ASSEMBLY
00329 typedef int tsl_t;
00330
00331 #define MUTEX_ALIGN sizeof(int)
00332 #define MUTEX_INIT(x) 0
00333 #define MUTEX_SET(x) (!uts_lock(x, 1))
00334 #define MUTEX_UNSET(x) (*(x) = 0)
00335 #endif
00336
00337
00338
00339
00340 #ifdef HAVE_MUTEX_X86_GCC_ASSEMBLY
00341 typedef unsigned char tsl_t;
00342 #endif
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353 #ifndef MUTEX_ALIGN
00354 #define MUTEX_ALIGN 1
00355 #endif
00356
00357 #define MUTEX_IGNORE 0x001
00358 #define MUTEX_SELF_BLOCK 0x002
00359 #define MUTEX_THREAD 0x004
00360
00361
00362 struct __mutex_t {
00363 #ifdef HAVE_MUTEX_THREADS
00364 #ifdef MUTEX_FIELDS
00365 MUTEX_FIELDS
00366 #else
00367 tsl_t tas;
00368 #endif
00369 u_int32_t spins;
00370 u_int32_t locked;
00371 #else
00372 u_int32_t off;
00373 u_int32_t pid;
00374 #endif
00375 u_int32_t mutex_set_wait;
00376 u_int32_t mutex_set_nowait;
00377
00378 u_int8_t flags;
00379 };
00380
00381
00382 #ifdef HAVE_MUTEX_THREADS
00383 #if defined(HAVE_MUTEX_PTHREADS) || defined(HAVE_MUTEX_SOLARIS_LWP) || defined(HAVE_MUTEX_UI_THREADS)
00384 #define __db_mutex_init(a, b, c, d) __db_pthread_mutex_init(a, b, d)
00385 #define __db_mutex_lock(a, b) __db_pthread_mutex_lock(a)
00386 #define __db_mutex_unlock(a) __db_pthread_mutex_unlock(a)
00387 #else
00388 #define __db_mutex_init(a, b, c, d) CDB___db_tas_mutex_init(a, b, d)
00389 #define __db_mutex_lock(a, b) CDB___db_tas_mutex_lock(a)
00390 #define __db_mutex_unlock(a) CDB___db_tas_mutex_unlock(a)
00391 #endif
00392 #else
00393 #define __db_mutex_init(a, b, c, d) __db_fcntl_mutex_init(a, b, c)
00394 #define __db_mutex_lock(a, b) __db_fcntl_mutex_lock(a, b)
00395 #define __db_mutex_unlock(a) __db_fcntl_mutex_unlock(a)
00396 #endif
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406 #ifdef DIAGNOSTIC
00407
00408
00409
00410
00411
00412 #define MUTEX_LOCK(mp, fh) \
00413 if (!F_ISSET((MUTEX *)(mp), MUTEX_IGNORE)) \
00414 (void)__db_mutex_lock(mp, fh); \
00415 if (DB_GLOBAL(db_pageyield)) \
00416 CDB___os_yield(NULL, 1);
00417 #else
00418 #define MUTEX_LOCK(mp, fh) \
00419 if (!F_ISSET((MUTEX *)(mp), MUTEX_IGNORE)) \
00420 (void)__db_mutex_lock(mp, fh);
00421 #endif
00422 #define MUTEX_UNLOCK(mp) \
00423 if (!F_ISSET((MUTEX *)(mp), MUTEX_IGNORE)) \
00424 (void)__db_mutex_unlock(mp);
00425 #define MUTEX_THREAD_LOCK(mp) \
00426 if (mp != NULL) \
00427 MUTEX_LOCK(mp, NULL)
00428 #define MUTEX_THREAD_UNLOCK(mp) \
00429 if (mp != NULL) \
00430 MUTEX_UNLOCK(mp)
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442 #define DB_FCNTL_OFF_GEN 0
00443 #define DB_FCNTL_OFF_LOCK 1
00444 #define DB_FCNTL_OFF_MPOOL 2