mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-09 14:21:03 +03:00
Code simplifications and comment improvements in support of structural
coverage testing. (CVS 6899) FossilOrigin-Name: 945251798144110787b197f9eb552a2dd4a25cb4
This commit is contained in:
34
src/mutex.c
34
src/mutex.c
@@ -14,7 +14,7 @@
|
||||
** This file contains code that is common across all mutex implementations.
|
||||
|
||||
**
|
||||
** $Id: mutex.c,v 1.30 2009/02/17 16:29:11 danielk1977 Exp $
|
||||
** $Id: mutex.c,v 1.31 2009/07/16 18:21:18 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -30,32 +30,16 @@ int sqlite3MutexInit(void){
|
||||
** install a mutex implementation via sqlite3_config() prior to
|
||||
** sqlite3_initialize() being called. This block copies pointers to
|
||||
** the default implementation into the sqlite3GlobalConfig structure.
|
||||
**
|
||||
** The danger is that although sqlite3_config() is not a threadsafe
|
||||
** API, sqlite3_initialize() is, and so multiple threads may be
|
||||
** attempting to run this function simultaneously. To guard write
|
||||
** access to the sqlite3GlobalConfig structure, the 'MASTER' static mutex
|
||||
** is obtained before modifying it.
|
||||
*/
|
||||
sqlite3_mutex_methods *p = sqlite3DefaultMutex();
|
||||
sqlite3_mutex *pMaster = 0;
|
||||
|
||||
rc = p->xMutexInit();
|
||||
if( rc==SQLITE_OK ){
|
||||
pMaster = p->xMutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
|
||||
assert(pMaster);
|
||||
p->xMutexEnter(pMaster);
|
||||
assert( sqlite3GlobalConfig.mutex.xMutexAlloc==0
|
||||
|| sqlite3GlobalConfig.mutex.xMutexAlloc==p->xMutexAlloc
|
||||
);
|
||||
if( !sqlite3GlobalConfig.mutex.xMutexAlloc ){
|
||||
sqlite3GlobalConfig.mutex = *p;
|
||||
}
|
||||
p->xMutexLeave(pMaster);
|
||||
}
|
||||
}else{
|
||||
rc = sqlite3GlobalConfig.mutex.xMutexInit();
|
||||
sqlite3_mutex_methods *pFrom = sqlite3DefaultMutex();
|
||||
sqlite3_mutex_methods *pTo = &sqlite3GlobalConfig.mutex;
|
||||
|
||||
memcpy(pTo, pFrom, offsetof(sqlite3_mutex_methods, xMutexAlloc));
|
||||
memcpy(&pTo->xMutexFree, &pFrom->xMutexFree,
|
||||
sizeof(*pTo) - offsetof(sqlite3_mutex_methods, xMutexFree));
|
||||
pTo->xMutexAlloc = pFrom->xMutexAlloc;
|
||||
}
|
||||
rc = sqlite3GlobalConfig.mutex.xMutexInit();
|
||||
}
|
||||
|
||||
return rc;
|
||||
|
||||
Reference in New Issue
Block a user