4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
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.
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
);
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
53 int lsmMutexTry(lsm_env
*pEnv
, lsm_mutex
*pMutex
){
54 return pEnv
->xMutexTry(pMutex
);
60 void lsmMutexLeave(lsm_env
*pEnv
, lsm_mutex
*pMutex
){
61 pEnv
->xMutexLeave(pMutex
);
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
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
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;