Merge trunk changes into this branch.
[sqlite.git] / ext / lsm1 / lsm_mutex.c
blobcb99b2a61e23a10d7c3c627f8bb0994ff5f757fe
1 /*
2 ** 2012-01-30
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.
11 *************************************************************************
13 ** Mutex functions for LSM.
15 #include "lsmInt.h"
18 ** Allocate a new mutex.
20 int lsmMutexNew(lsm_env *pEnv, lsm_mutex **ppNew){
21 return pEnv->xMutexNew(pEnv, ppNew);
25 ** Return a handle for one of the static mutexes.
27 int lsmMutexStatic(lsm_env *pEnv, int iMutex, lsm_mutex **ppStatic){
28 return pEnv->xMutexStatic(pEnv, iMutex, ppStatic);
32 ** Free a mutex allocated by lsmMutexNew().
34 void lsmMutexDel(lsm_env *pEnv, lsm_mutex *pMutex){
35 if( pMutex ) pEnv->xMutexDel(pMutex);
39 ** Enter a mutex.
41 void lsmMutexEnter(lsm_env *pEnv, lsm_mutex *pMutex){
42 pEnv->xMutexEnter(pMutex);
46 ** Attempt to enter a mutex, but do not block. If successful, return zero.
47 ** Otherwise, if the mutex is already held by some other thread and is not
48 ** entered, return non zero.
50 ** Each successful call to this function must be matched by a call to
51 ** lsmMutexLeave().
53 int lsmMutexTry(lsm_env *pEnv, lsm_mutex *pMutex){
54 return pEnv->xMutexTry(pMutex);
58 ** Leave a mutex.
60 void lsmMutexLeave(lsm_env *pEnv, lsm_mutex *pMutex){
61 pEnv->xMutexLeave(pMutex);
64 #ifndef NDEBUG
66 ** Return non-zero if the mutex passed as the second argument is held
67 ** by the calling thread, or zero otherwise. If the implementation is not
68 ** able to tell if the mutex is held by the caller, it should return
69 ** non-zero.
71 ** This function is only used as part of assert() statements.
73 int lsmMutexHeld(lsm_env *pEnv, lsm_mutex *pMutex){
74 return pEnv->xMutexHeld ? pEnv->xMutexHeld(pMutex) : 1;
78 ** Return non-zero if the mutex passed as the second argument is not
79 ** held by the calling thread, or zero otherwise. If the implementation
80 ** is not able to tell if the mutex is held by the caller, it should
81 ** return non-zero.
83 ** This function is only used as part of assert() statements.
85 int lsmMutexNotHeld(lsm_env *pEnv, lsm_mutex *pMutex){
86 return pEnv->xMutexNotHeld ? pEnv->xMutexNotHeld(pMutex) : 1;
88 #endif