/* ** The sqlite3_mutex_alloc() routine allocates a new ** mutex and returns a pointer to it. If it returns NULL ** that means that a mutex could not be allocated. */ private static sqlite3_mutex debugMutexAlloc(int id) { sqlite3_debug_mutex[] aStatic = new sqlite3_debug_mutex[6]; sqlite3_debug_mutex pNew = null; switch (id) { case SQLITE_MUTEX_FAST: case SQLITE_MUTEX_RECURSIVE: { pNew = new sqlite3_debug_mutex(); //sqlite3Malloc(sizeof(*pNew)); if (pNew != null) { pNew.id = id; pNew.cnt = 0; } break; } default: { Debug.Assert(id - 2 >= 0); Debug.Assert(id - 2 < aStatic.Length); //(int)(sizeof(aStatic)/sizeof(aStatic[0])) ); pNew = aStatic[id - 2]; pNew.id = id; break; } } return(pNew); }
/* ** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt ** to enter a mutex. If another thread is already within the mutex, ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return ** SQLITE_BUSY. The sqlite3_mutex_try() interface returns SQLITE_OK ** upon successful entry. Mutexes created using SQLITE_MUTEX_RECURSIVE can ** be entered multiple times by the same thread. In such cases the, ** mutex must be exited an equal number of times before another thread ** can enter. If the same thread tries to enter any other kind of mutex ** more than once, the behavior is undefined. */ private static void debugMutexEnter(sqlite3_mutex pX) { sqlite3_debug_mutex p = (sqlite3_debug_mutex)pX; Debug.Assert(p.id == SQLITE_MUTEX_RECURSIVE || debugMutexNotheld(p)); p.cnt++; }
private static int debugMutexTry(sqlite3_mutex pX) { sqlite3_debug_mutex p = (sqlite3_debug_mutex)pX; Debug.Assert(p.id == SQLITE_MUTEX_RECURSIVE || debugMutexNotheld(p)); p.cnt++; return(SQLITE_OK); }
/* ** This routine deallocates a previously allocated mutex. */ private static void debugMutexFree(sqlite3_mutex pX) { sqlite3_debug_mutex p = (sqlite3_debug_mutex)pX; Debug.Assert(p.cnt == 0); Debug.Assert(p.id == SQLITE_MUTEX_FAST || p.id == SQLITE_MUTEX_RECURSIVE); //sqlite3_free(ref p); }
/* ** The sqlite3_mutex_leave() routine exits a mutex that was ** previously entered by the same thread. The behavior ** is undefined if the mutex is not currently entered or ** is not currently allocated. SQLite will never do either. */ static void debugMutexLeave(sqlite3_mutex pX) { sqlite3_debug_mutex p = (sqlite3_debug_mutex)pX; Debug.Assert(debugMutexHeld(p)); p.cnt--; Debug.Assert(p.id == SQLITE_MUTEX_RECURSIVE || debugMutexNotheld(p)); }
private static bool debugMutexNotheld(sqlite3_mutex pX) { sqlite3_debug_mutex p = (sqlite3_debug_mutex)pX; return(p == null || p.cnt == 0); }
/* ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are ** intended for use inside Debug.Assert() statements. */ static bool debugMutexHeld(sqlite3_mutex pX) { sqlite3_debug_mutex p = (sqlite3_debug_mutex)pX; return(p == null || p.cnt > 0); }
/* ** The sqlite3_mutex_alloc() routine allocates a new ** mutex and returns a pointer to it. If it returns NULL ** that means that a mutex could not be allocated. */ static sqlite3_mutex debugMutexAlloc( int id ) { sqlite3_debug_mutex[] aStatic = new sqlite3_debug_mutex[6]; sqlite3_debug_mutex pNew = null; switch ( id ) { case SQLITE_MUTEX_FAST: case SQLITE_MUTEX_RECURSIVE: { pNew = new sqlite3_debug_mutex();//sqlite3Malloc(sizeof(*pNew)); if ( pNew != null ) { pNew.id = id; pNew.cnt = 0; } break; } default: { Debug.Assert( id - 2 >= 0 ); Debug.Assert( id - 2 < aStatic.Length );//(int)(sizeof(aStatic)/sizeof(aStatic[0])) ); pNew = aStatic[id - 2]; pNew.id = id; break; } } return pNew; }