| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #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[SQLITE_MUTEX_STATIC_VFS3 - 1]; |
| 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: { |
| #ifdef SQLITE_ENABLE_API_ARMOR |
| if( id-2<0 || id-2>=ArraySize(aStatic) ){ |
| (void)SQLITE_MISUSE_BKPT; |
| return 0; |
| } |
| #endif |
| 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 ); |
| if( p->id==SQLITE_MUTEX_RECURSIVE || p->id==SQLITE_MUTEX_FAST ){ |
| sqlite3_free(p); |
| }else{ |
| #ifdef SQLITE_ENABLE_API_ARMOR |
| (void)SQLITE_MISUSE_BKPT; |
| #endif |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| 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 |
|
|