aboutsummaryrefslogtreecommitdiff
path: root/src/os_unix.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2006-01-18 14:06:37 +0000
committerdrh <drh@noemail.net>2006-01-18 14:06:37 +0000
commita3fad6f5f3f480dc891d8d3df372bbc4e3da9e20 (patch)
tree1b7b06d5deb8c339a25a6b08d752ef636a1e67f0 /src/os_unix.c
parent950f054cec20913cbea37bddb8068adbfeecf933 (diff)
downloadsqlite-a3fad6f5f3f480dc891d8d3df372bbc4e3da9e20.tar.gz
sqlite-a3fad6f5f3f480dc891d8d3df372bbc4e3da9e20.zip
Convert the unix driver to use a recusive mutex. Similar changes to the
windows driver are pending. (CVS 2968) FossilOrigin-Name: 8830bbbac8e0c9243956aac42dc9f86a0bd1fa07
Diffstat (limited to 'src/os_unix.c')
-rw-r--r--src/os_unix.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/src/os_unix.c b/src/os_unix.c
index 9263744b3..35d29ad3c 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -1667,7 +1667,9 @@ int sqlite3UnixSleep(int ms){
*/
static int inMutex = 0;
#ifdef SQLITE_UNIX_THREADS
-static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_t mutexOwner;
+static pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t mutex2 = PTHREAD_MUTEX_INITIALIZER;
#endif
/*
@@ -1682,16 +1684,27 @@ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
*/
void sqlite3UnixEnterMutex(){
#ifdef SQLITE_UNIX_THREADS
- pthread_mutex_lock(&mutex);
+ pthread_mutex_lock(&mutex1);
+ if( inMutex==0 ){
+ pthread_mutex_lock(&mutex2);
+ mutexOwner = pthread_self();
+ }
+ pthread_mutex_unlock(&mutex1);
#endif
- assert( !inMutex );
- inMutex = 1;
+ inMutex++;
}
void sqlite3UnixLeaveMutex(){
- assert( inMutex );
- inMutex = 0;
+ assert( inMutex>0 );
#ifdef SQLITE_UNIX_THREADS
- pthread_mutex_unlock(&mutex);
+ assert( pthread_equal(mutexOwner, pthread_self()) );
+ pthread_mutex_lock(&mutex1);
+ inMutex--;
+ if( inMutex==0 ){
+ pthread_mutex_unlock(&mutex2);
+ }
+ pthread_mutex_unlock(&mutex1);
+#else
+ inMutex--;
#endif
}
@@ -1699,7 +1712,11 @@ void sqlite3UnixLeaveMutex(){
** Return TRUE if we are currently within the mutex and FALSE if not.
*/
int sqlite3UnixInMutex(){
+#ifdef SQLITE_UNIX_THREADS
+ return inMutex && pthread_equal(mutexOwner, pthread_self());
+#else
return inMutex;
+#endif
}
/*