mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-09 14:21:03 +03:00
Import common changes from the mutex initialization branch.
FossilOrigin-Name: 334720c01722478af0d3dfd6fe8bafd88ba09f49
This commit is contained in:
11
src/mutex.c
11
src/mutex.c
@@ -22,7 +22,7 @@
|
||||
** allocate a mutex while the system is uninitialized.
|
||||
*/
|
||||
static SQLITE_WSD int mutexIsInit = 0;
|
||||
#endif /* SQLITE_DEBUG */
|
||||
#endif /* SQLITE_DEBUG && !defined(SQLITE_MUTEX_OMIT) */
|
||||
|
||||
|
||||
#ifndef SQLITE_MUTEX_OMIT
|
||||
@@ -56,6 +56,7 @@ int sqlite3MutexInit(void){
|
||||
sqlite3MemoryBarrier();
|
||||
pTo->xMutexAlloc = pFrom->xMutexAlloc;
|
||||
}
|
||||
assert( sqlite3GlobalConfig.mutex.xMutexInit );
|
||||
rc = sqlite3GlobalConfig.mutex.xMutexInit();
|
||||
|
||||
#ifdef SQLITE_DEBUG
|
||||
@@ -90,6 +91,7 @@ sqlite3_mutex *sqlite3_mutex_alloc(int id){
|
||||
if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0;
|
||||
if( id>SQLITE_MUTEX_RECURSIVE && sqlite3MutexInit() ) return 0;
|
||||
#endif
|
||||
assert( sqlite3GlobalConfig.mutex.xMutexAlloc );
|
||||
return sqlite3GlobalConfig.mutex.xMutexAlloc(id);
|
||||
}
|
||||
|
||||
@@ -98,6 +100,7 @@ sqlite3_mutex *sqlite3MutexAlloc(int id){
|
||||
return 0;
|
||||
}
|
||||
assert( GLOBAL(int, mutexIsInit) );
|
||||
assert( sqlite3GlobalConfig.mutex.xMutexAlloc );
|
||||
return sqlite3GlobalConfig.mutex.xMutexAlloc(id);
|
||||
}
|
||||
|
||||
@@ -106,6 +109,7 @@ sqlite3_mutex *sqlite3MutexAlloc(int id){
|
||||
*/
|
||||
void sqlite3_mutex_free(sqlite3_mutex *p){
|
||||
if( p ){
|
||||
assert( sqlite3GlobalConfig.mutex.xMutexFree );
|
||||
sqlite3GlobalConfig.mutex.xMutexFree(p);
|
||||
}
|
||||
}
|
||||
@@ -116,6 +120,7 @@ void sqlite3_mutex_free(sqlite3_mutex *p){
|
||||
*/
|
||||
void sqlite3_mutex_enter(sqlite3_mutex *p){
|
||||
if( p ){
|
||||
assert( sqlite3GlobalConfig.mutex.xMutexEnter );
|
||||
sqlite3GlobalConfig.mutex.xMutexEnter(p);
|
||||
}
|
||||
}
|
||||
@@ -127,6 +132,7 @@ void sqlite3_mutex_enter(sqlite3_mutex *p){
|
||||
int sqlite3_mutex_try(sqlite3_mutex *p){
|
||||
int rc = SQLITE_OK;
|
||||
if( p ){
|
||||
assert( sqlite3GlobalConfig.mutex.xMutexTry );
|
||||
return sqlite3GlobalConfig.mutex.xMutexTry(p);
|
||||
}
|
||||
return rc;
|
||||
@@ -140,6 +146,7 @@ int sqlite3_mutex_try(sqlite3_mutex *p){
|
||||
*/
|
||||
void sqlite3_mutex_leave(sqlite3_mutex *p){
|
||||
if( p ){
|
||||
assert( sqlite3GlobalConfig.mutex.xMutexLeave );
|
||||
sqlite3GlobalConfig.mutex.xMutexLeave(p);
|
||||
}
|
||||
}
|
||||
@@ -150,9 +157,11 @@ void sqlite3_mutex_leave(sqlite3_mutex *p){
|
||||
** intended for use inside assert() statements.
|
||||
*/
|
||||
int sqlite3_mutex_held(sqlite3_mutex *p){
|
||||
assert( p==0 || sqlite3GlobalConfig.mutex.xMutexHeld );
|
||||
return p==0 || sqlite3GlobalConfig.mutex.xMutexHeld(p);
|
||||
}
|
||||
int sqlite3_mutex_notheld(sqlite3_mutex *p){
|
||||
assert( p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld );
|
||||
return p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld(p);
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user