/* ** Allocate a countable mutex */ static sqlite3_mutex counterMutexAlloc( int eType ) { sqlite3_mutex pReal; sqlite3_mutex pRet = null; Debug.Assert( g.isInit ); Debug.Assert( eType < 8 && eType >= 0 ); pReal = g.m.xMutexAlloc( eType ); if ( null == pReal ) return null; if ( eType == SQLITE_MUTEX_FAST || eType == SQLITE_MUTEX_RECURSIVE ) { pRet = new sqlite3_mutex(); ;//(sqlite3_mutex)malloc( sizeof( sqlite3_mutex ) ); } else { pRet = g.aStatic[eType - 2]; } pRet.eType = eType; pRet.pReal = pReal; return pRet; }
static void noopMutexFree(sqlite3_mutex *p){ return; }
static int noopMutexTry(sqlite3_mutex *p){ return SQLITE_OK; }
/* ** 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. If a NULL pointer is passed as an argument ** this function is a no-op. */ static void sqlite3_mutex_leave(sqlite3_mutex p){ if( p !=null){ sqlite3GlobalConfig.mutex.xMutexLeave(p); } }
public Mem0Global( int nScratchFree, int nPageFree, sqlite3_mutex mutex, sqlite3_int64 alarmThreshold, dxalarmCallback alarmCallback, object alarmArg, int Byte_Allocation, int Int_Allocation, int Mem_Allocation, int BtCursor_Allocation ) { this.nScratchFree = nScratchFree; this.nPageFree = nPageFree; this.mutex = mutex; this.alarmThreshold = alarmThreshold; this.alarmCallback = alarmCallback; this.alarmArg = alarmArg; this.msByte.next = -1; this.msInt.next = -1; this.msMem.next = -1; this.aByteSize = new int[] { 32, 256, 1024, 8192, 0 }; this.aByte_used = new int[] { -1, -1, -1, -1, -1 }; this.aByte = new byte[this.aByteSize.Length][][]; for ( int i = 0; i < this.aByteSize.Length; i++ ) this.aByte[i] = new byte[Byte_Allocation][]; this.aInt = new int[Int_Allocation][]; this.aMem = new Mem[Mem_Allocation <= 4 ? 4 : Mem_Allocation]; this.aBtCursor = new BtCursor[BtCursor_Allocation <= 4 ? 4 : BtCursor_Allocation]; }
static bool sqlite3_mutex_notheld(sqlite3_mutex p) { return true; }
/* ** Obtain the mutex p. If some other thread already has the mutex, block ** until it can be obtained. */ static void sqlite3_mutex_enter(sqlite3_mutex p){ if( p !=null){ sqlite3GlobalConfig.mutex.xMutexEnter(p); } }
/* Return true if the countable mutex is not currently held */ static bool counterMutexNotheld( sqlite3_mutex p ) { return g.m.xMutexNotheld( p.pReal ); }
/* ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are ** intended for use inside assert() statements. */ private static bool sqlite3_mutex_held(sqlite3_mutex p) { return p == null || sqlite3GlobalConfig.mutex.xMutexHeld(p); }
/* Leave a mutex */ static void counterMutexLeave( sqlite3_mutex p ) { Debug.Assert( g.isInit ); g.m.xMutexLeave( p.pReal ); }
public sqlite3_mutex[] aStatic = new sqlite3_mutex[6]; /* The six static mutexes */ public test_mutex_globals() { for ( int i = 0; i < aStatic.Length; i++ ) aStatic[i] = new sqlite3_mutex(); }
/* ** Try to enter a mutex. Return true on success. */ static int counterMutexTry( sqlite3_mutex p ) { Debug.Assert( g.isInit ); g.aCounter[p.eType]++; if ( g.disableTry ) return SQLITE_BUSY; return g.m.xMutexTry( p.pReal ); }
/* ** Enter a countable mutex. Block until entry is safe. */ static void counterMutexEnter( sqlite3_mutex p ) { Debug.Assert( g.isInit ); g.aCounter[p.eType]++; g.m.xMutexEnter( p.pReal ); }
/* ** Free a countable mutex */ static void counterMutexFree( sqlite3_mutex p ) { Debug.Assert( g.isInit ); g.m.xMutexFree( p.pReal ); if ( p.eType == SQLITE_MUTEX_FAST || p.eType == SQLITE_MUTEX_RECURSIVE ) { p = null;//free(p); } }
/* ** 2008 October 07 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains the C functions that implement mutexes. ** ** This implementation in this file does not provide any mutual ** exclusion and is thus suitable for use only in applications ** that use SQLite in a single thread. The routines defined ** here are place-holders. Applications can substitute working ** mutex routines at start-time using the ** ** sqlite3_config(SQLITE_CONFIG_MUTEX,...) ** ** interface. ** ** If compiled with SQLITE_DEBUG, then additional logic is inserted ** that does error checking on mutexes to make sure they are being ** called correctly. ************************************************************************* ** Included in SQLite3 port to C#-SQLite; 2008 Noah B Hart ** C#-SQLite is an independent reimplementation of the SQLite software library ** ** SQLITE_SOURCE_ID: 2009-12-07 16:39:13 1ed88e9d01e9eda5cbc622e7614277f29bcc551c ** ************************************************************************* */ //#include "sqliteInt.h" /* ** Stub routines for all mutex methods. ** ** This routines provide no mutual exclusion or error checking. */ static int noopMutexHeld(sqlite3_mutex p) { return 1; }
/* ** 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. */ 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++; }
static void noopMutexLeave(sqlite3_mutex p) { }
/* ** This routine deallocates a previously allocated mutex. */ 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); }
/* ** Free a dynamic mutex. */ static void sqlite3_mutex_free( sqlite3_mutex p){ if( p!=null ){ sqlite3GlobalConfig.mutex.xMutexFree( p); } }
static void noopMutexEnter(sqlite3_mutex p) { }
/* ** Obtain the mutex p. If successful, return SQLITE_OK. Otherwise, if another ** thread holds the mutex and it cannot be obtained, return SQLITE_BUSY. */ static int sqlite3_mutex_try(sqlite3_mutex p){ int rc = SQLITE_OK; if( p!=null ){ return sqlite3GlobalConfig.mutex.xMutexTry(p); } return rc; }
/* ** 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 ) ); }
static bool sqlite3_mutex_notheld(sqlite3_mutex p){ return p == null || sqlite3GlobalConfig.mutex.xMutexNotheld( p ); }
static bool debugMutexNotheld( sqlite3_mutex pX ) { sqlite3_debug_mutex p = (sqlite3_debug_mutex)pX; return p == null || p.cnt == 0; }
static int noopMutexNotheld(sqlite3_mutex *p){ return 1; }
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; }
static void noopMutexEnter(sqlite3_mutex *p){ return; }
static void noopMutexFree(sqlite3_mutex p) { }
static void noopMutexLeave(sqlite3_mutex *p){ return; }
/* ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are ** intended for use inside assert() statements. */ static bool sqlite3_mutex_held(sqlite3_mutex p){ if ( p != null && p.trace != 0 ) printf( "sqlite3_mutex_held {0} ({1}) with nRef={2}\n", p.GetHashCode(), p.owner, p.nRef ); return p==null || sqlite3GlobalConfig.mutex.xMutexHeld(p); }