1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-09 14:21:03 +03:00

Create a fresh pthread_mutexattr_t every time a recursive mutex is

allocated.  Ticket #2588. (CVS 4300)

FossilOrigin-Name: 3d746343add3feb9d208302a00b419d71d6ba246
This commit is contained in:
drh
2007-08-25 16:31:29 +00:00
parent 8bacf9743f
commit 4b6b4ab0d2
3 changed files with 13 additions and 21 deletions

View File

@@ -12,7 +12,7 @@
** This file contains the C functions that implement mutexes for
** use by the SQLite core.
**
** $Id: mutex.c,v 1.12 2007/08/25 16:21:30 drh Exp $
** $Id: mutex.c,v 1.13 2007/08/25 16:31:30 drh Exp $
*/
/*
** If SQLITE_MUTEX_APPDEF is defined, then this whole module is
@@ -289,22 +289,14 @@ sqlite3_mutex *sqlite3_mutex_alloc(int iType){
sqlite3_mutex *p;
switch( iType ){
case SQLITE_MUTEX_RECURSIVE: {
static pthread_mutex_t initMutex = PTHREAD_MUTEX_INITIALIZER;
static int isInit = 0;
static pthread_mutexattr_t recursiveAttr;
if( !isInit ){
pthread_mutex_lock(&initMutex);
if( !isInit ){
pthread_mutexattr_init(&recursiveAttr);
pthread_mutexattr_settype(&recursiveAttr, PTHREAD_MUTEX_RECURSIVE);
}
isInit = 1;
pthread_mutex_unlock(&initMutex);
}
p = sqlite3MallocZero( sizeof(*p) );
if( p ){
p->id = iType;
pthread_mutexattr_t recursiveAttr;
pthread_mutexattr_init(&recursiveAttr);
pthread_mutexattr_settype(&recursiveAttr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&p->mutex, &recursiveAttr);
pthread_mutexattr_destroy(&recursiveAttr);
p->id = iType;
}
break;
}