This source file includes following definitions.
- noopMutexInit
- noopMutexEnd
- noopMutexAlloc
- noopMutexFree
- noopMutexEnter
- noopMutexTry
- noopMutexLeave
- sqlite3NoopMutex
- debugMutexHeld
- debugMutexNotheld
- debugMutexInit
- debugMutexEnd
- debugMutexAlloc
- debugMutexFree
- debugMutexEnter
- debugMutexTry
- debugMutexLeave
- sqlite3NoopMutex
- sqlite3DefaultMutex
#include "sqliteInt.h"
#ifndef SQLITE_MUTEX_OMIT
#ifndef SQLITE_DEBUG
static int noopMutexInit(void){ return SQLITE_OK; }
static int noopMutexEnd(void){ return SQLITE_OK; }
static sqlite3_mutex *noopMutexAlloc(int id){
UNUSED_PARAMETER(id);
return (sqlite3_mutex*)8;
}
static void noopMutexFree(sqlite3_mutex *p){ UNUSED_PARAMETER(p); return; }
static void noopMutexEnter(sqlite3_mutex *p){ UNUSED_PARAMETER(p); return; }
static int noopMutexTry(sqlite3_mutex *p){
UNUSED_PARAMETER(p);
return SQLITE_OK;
}
static void noopMutexLeave(sqlite3_mutex *p){ UNUSED_PARAMETER(p); return; }
sqlite3_mutex_methods const *sqlite3NoopMutex(void){
static const sqlite3_mutex_methods sMutex = {
noopMutexInit,
noopMutexEnd,
noopMutexAlloc,
noopMutexFree,
noopMutexEnter,
noopMutexTry,
noopMutexLeave,
0,
0,
};
return &sMutex;
}
#endif
#ifdef SQLITE_DEBUG
typedef struct sqlite3_debug_mutex {
int id;
int cnt;
} sqlite3_debug_mutex;
static int debugMutexHeld(sqlite3_mutex *pX){
sqlite3_debug_mutex *p = (sqlite3_debug_mutex*)pX;
return p==0 || p->cnt>0;
}
static int debugMutexNotheld(sqlite3_mutex *pX){
sqlite3_debug_mutex *p = (sqlite3_debug_mutex*)pX;
return p==0 || p->cnt==0;
}
static int debugMutexInit(void){ return SQLITE_OK; }
static int debugMutexEnd(void){ return SQLITE_OK; }
static sqlite3_mutex *debugMutexAlloc(int id){
static sqlite3_debug_mutex aStatic[6];
sqlite3_debug_mutex *pNew = 0;
switch( id ){
case SQLITE_MUTEX_FAST:
case SQLITE_MUTEX_RECURSIVE: {
pNew = sqlite3Malloc(sizeof(*pNew));
if( pNew ){
pNew->id = id;
pNew->cnt = 0;
}
break;
}
default: {
assert( id-2 >= 0 );
assert( id-2 < (int)(sizeof(aStatic)/sizeof(aStatic[0])) );
pNew = &aStatic[id-2];
pNew->id = id;
break;
}
}
return (sqlite3_mutex*)pNew;
}
static void debugMutexFree(sqlite3_mutex *pX){
sqlite3_debug_mutex *p = (sqlite3_debug_mutex*)pX;
assert( p->cnt==0 );
assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE );
sqlite3_free(p);
}
static void debugMutexEnter(sqlite3_mutex *pX){
sqlite3_debug_mutex *p = (sqlite3_debug_mutex*)pX;
assert( p->id==SQLITE_MUTEX_RECURSIVE || debugMutexNotheld(pX) );
p->cnt++;
}
static int debugMutexTry(sqlite3_mutex *pX){
sqlite3_debug_mutex *p = (sqlite3_debug_mutex*)pX;
assert( p->id==SQLITE_MUTEX_RECURSIVE || debugMutexNotheld(pX) );
p->cnt++;
return SQLITE_OK;
}
static void debugMutexLeave(sqlite3_mutex *pX){
sqlite3_debug_mutex *p = (sqlite3_debug_mutex*)pX;
assert( debugMutexHeld(pX) );
p->cnt--;
assert( p->id==SQLITE_MUTEX_RECURSIVE || debugMutexNotheld(pX) );
}
sqlite3_mutex_methods const *sqlite3NoopMutex(void){
static const sqlite3_mutex_methods sMutex = {
debugMutexInit,
debugMutexEnd,
debugMutexAlloc,
debugMutexFree,
debugMutexEnter,
debugMutexTry,
debugMutexLeave,
debugMutexHeld,
debugMutexNotheld
};
return &sMutex;
}
#endif
#ifdef SQLITE_MUTEX_NOOP
sqlite3_mutex_methods const *sqlite3DefaultMutex(void){
return sqlite3NoopMutex();
}
#endif
#endif