aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2009-08-18 15:33:44 +0000
committerdrh <drh@noemail.net>2009-08-18 15:33:44 +0000
commit1b25753b30781a3d2a2fc7ed263b4d920dc010e9 (patch)
tree15ac28036c44b675968a130bf984507ee4eec6cb /src
parent7c6791c8b1b78fe03665867484bddf6fac9663b2 (diff)
downloadsqlite-1b25753b30781a3d2a2fc7ed263b4d920dc010e9.tar.gz
sqlite-1b25753b30781a3d2a2fc7ed263b4d920dc010e9.zip
Move the allocation of the memsys5 mutex into the initializer.
FossilOrigin-Name: 4e377a09c194e90581ef00fd3a213e936b4e648a
Diffstat (limited to 'src')
-rw-r--r--src/mem5.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/mem5.c b/src/mem5.c
index 8deda14e9..e69676332 100644
--- a/src/mem5.c
+++ b/src/mem5.c
@@ -188,9 +188,6 @@ static void memsys5Link(int i, int iLogsize){
** sqlite3GlobalConfig.bMemStat is true.
*/
static void memsys5Enter(void){
- if( sqlite3GlobalConfig.bMemstat==0 && mem5.mutex==0 ){
- mem5.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
- }
sqlite3_mutex_enter(mem5.mutex);
}
static void memsys5Leave(void){
@@ -447,6 +444,9 @@ static int memsys5Log(int iValue){
/*
** Initialize the memory allocator.
+**
+** This routine is not threadsafe. The caller must be holding a mutex
+** to prevent multiple threads from entering at the same time.
*/
static int memsys5Init(void *NotUsed){
int ii; /* Loop counter */
@@ -457,6 +457,9 @@ static int memsys5Init(void *NotUsed){
UNUSED_PARAMETER(NotUsed);
+ /* For the purposes of this routine, disable the mutex */
+ mem5.mutex = 0;
+
/* The size of a Mem5Link object must be a power of two. Verify that
** this is case.
*/
@@ -491,6 +494,11 @@ static int memsys5Init(void *NotUsed){
assert((iOffset+nAlloc)>mem5.nBlock);
}
+ /* If a mutex is required for normal operation, allocate one */
+ if( sqlite3GlobalConfig.bMemstat==0 && mem5.mutex==0 ){
+ mem5.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
+ }
+
return SQLITE_OK;
}