]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Reorganize the code for the homegrown recursive mutexes. Fix a place
authordrh <drh@noemail.net>
Wed, 28 Nov 2007 14:04:57 +0000 (14:04 +0000)
committerdrh <drh@noemail.net>
Wed, 28 Nov 2007 14:04:57 +0000 (14:04 +0000)
in the previous check-in where the #ifdef label was incorrect.
Ticket #2804. (CVS 4576)

FossilOrigin-Name: 542e11f954983ae26fef4ea850c8b2a20f738edd

manifest
manifest.uuid
src/mutex_unix.c

index e8fe5bc7cf1f2e5576e1d6c060503b4563a8b195..be10b93121238030798ac710c5b54e60c5c1e4f6 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Clarify\sthe\sconditions\sunder\swhich\shomegrown\srecursive\smutexes\swork\n(they\srequire\sa\scoherent\scache)\sand\sonly\senable\sthem\sif\sthere\sis\san\nexplicit\s#define\sso\sas\sto\savoid\saccidental\suse\son\splatforms\sthat\sdo\nnot\smeet\sthe\sconstraints.\s\sTicket\s#2805.\s(CVS\s4575)
-D 2007-11-28T13:55:55
+C Reorganize\sthe\scode\sfor\sthe\shomegrown\srecursive\smutexes.\s\sFix\sa\splace\nin\sthe\sprevious\scheck-in\swhere\sthe\s#ifdef\slabel\swas\sincorrect.\nTicket\s#2804.\s(CVS\s4576)
+D 2007-11-28T14:04:57
 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
 F Makefile.in 35396fd58890420b29edcf27b6c0e2d054862a6b
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -110,7 +110,7 @@ F src/mem3.c a9857cf92c9e4c889184b2cf1ca1839c801fc942
 F src/mutex.c 3259f62c2429967aee6dc112117a6d2f499ef061
 F src/mutex.h 079fa6fe9da18ceb89e79012c010594c6672addb
 F src/mutex_os2.c 7fe4773e98ed74a63b2e54fc557929eb155f6269
-F src/mutex_unix.c 94da6981f99f541fa712eae2394a02abe28d8d81
+F src/mutex_unix.c a6e111947a3cdaa2cda394ed060d7f496fcb4af8
 F src/mutex_w32.c 6e197765f283815496193e78e9548b5d0e53b68e
 F src/os.c 8360932f1450b2b45edb608a3b184b031f7d00cc
 F src/os.h b75506ab40d222300f38023acb56fe08df5ffe33
@@ -593,7 +593,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
-P f731fa6bb398d8af621af17dc0677dd0f715c4a7
-R 4e1efce73c2c2dbd0b0a966f60aca236
+P 80299eebddba9aac4c1bc36ffa2b440bffbf1751
+R 91aabeff7afc14d1c39bb734a20c5788
 U drh
-Z e8231964a01316a62ce8f3b57c4b7533
+Z 5760708bd767145f7cd934d8b8502186
index bf26b8587ebc50f3c1efabc4808930d6a578a4c7..b38267fad60a7945fc25686dc360670ebcb1fdd9 100644 (file)
@@ -1 +1 @@
-80299eebddba9aac4c1bc36ffa2b440bffbf1751
\ No newline at end of file
+542e11f954983ae26fef4ea850c8b2a20f738edd
\ No newline at end of file
index 4b7971bc862edd4e6325e24fb8e3f33afc41a296..93e7e9a190d0c2291356f3c797568cc9bd902e17 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** This file contains the C functions that implement mutexes for pthreads
 **
-** $Id: mutex_unix.c,v 1.4 2007/11/28 13:55:55 drh Exp $
+** $Id: mutex_unix.c,v 1.5 2007/11/28 14:04:57 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -94,17 +94,17 @@ sqlite3_mutex *sqlite3_mutex_alloc(int iType){
     case SQLITE_MUTEX_RECURSIVE: {
       p = sqlite3MallocZero( sizeof(*p) );
       if( p ){
-#ifndef SQLITE_HOMEGROWN_RECURSIVE_MUTEX
+#ifdef SQLITE_HOMEGROWN_RECURSIVE_MUTEX
+        /* If recursive mutexes are not available, we will have to
+        ** build our own.  See below. */
+        pthread_mutex_init(&p->mutex, 0);
+#else
         /* Use a recursive mutex if it is available */
         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);
-#else
-        /* If recursive mutexes are not available, we will have to
-        ** build our own.  See below. */
-        pthread_mutex_init(&p->mutex, 0);
 #endif
         p->id = iType;
       }
@@ -158,13 +158,7 @@ void sqlite3_mutex_enter(sqlite3_mutex *p){
   assert( p );
   assert( p->id==SQLITE_MUTEX_RECURSIVE || sqlite3_mutex_notheld(p) );
 
-#ifndef SQLITE_HOMEGROWN_RECURSIVE_MUTEX
-  /* Use the built-in recursive mutexes if they are available.
-  */
-  pthread_mutex_lock(&p->mutex);
-  p->owner = pthread_self();
-  p->nRef++;
-#else
+#ifdef SQLITE_HOMEGROWN_RECURSIVE_MUTEX
   /* If recursive mutexes are not available, then we have to grow
   ** our own.  This implementation assumes that pthread_equal()
   ** is atomic - that it cannot be deceived into thinking self
@@ -186,6 +180,12 @@ void sqlite3_mutex_enter(sqlite3_mutex *p){
       p->nRef = 1;
     }
   }
+#else
+  /* Use the built-in recursive mutexes if they are available.
+  */
+  pthread_mutex_lock(&p->mutex);
+  p->owner = pthread_self();
+  p->nRef++;
 #endif
 
 #ifdef SQLITE_DEBUG
@@ -199,17 +199,7 @@ int sqlite3_mutex_try(sqlite3_mutex *p){
   assert( p );
   assert( p->id==SQLITE_MUTEX_RECURSIVE || sqlite3_mutex_notheld(p) );
 
-#ifndef SQLITE_HOMEGROWN_RECURSIVE_MUTEX
-  /* Use the built-in recursive mutexes if they are available.
-  */
-  if( pthread_mutex_trylock(&p->mutex)==0 ){
-    p->owner = pthread_self();
-    p->nRef++;
-    rc = SQLITE_OK;
-  }else{
-    rc = SQLITE_BUSY;
-  }
-#else
+#ifdef SQLITE_HOMEGROWN_RECURSIVE_MUTEX
   /* If recursive mutexes are not available, then we have to grow
   ** our own.  This implementation assumes that pthread_equal()
   ** is atomic - that it cannot be deceived into thinking self
@@ -234,6 +224,16 @@ int sqlite3_mutex_try(sqlite3_mutex *p){
       rc = SQLITE_BUSY;
     }
   }
+#else
+  /* Use the built-in recursive mutexes if they are available.
+  */
+  if( pthread_mutex_trylock(&p->mutex)==0 ){
+    p->owner = pthread_self();
+    p->nRef++;
+    rc = SQLITE_OK;
+  }else{
+    rc = SQLITE_BUSY;
+  }
 #endif
 
 #ifdef SQLITE_DEBUG
@@ -256,12 +256,12 @@ void sqlite3_mutex_leave(sqlite3_mutex *p){
   p->nRef--;
   assert( p->nRef==0 || p->id==SQLITE_MUTEX_RECURSIVE );
 
-#ifdef PTHREAD_RECURSIVE_MUTEX
-  pthread_mutex_unlock(&p->mutex);
-#else
+#ifdef SQLITE_HOMEGROWN_RECURSIVE_MUTEX
   if( p->nRef==0 ){
     pthread_mutex_unlock(&p->mutex);
   }
+#else
+  pthread_mutex_unlock(&p->mutex);
 #endif
 
 #ifdef SQLITE_DEBUG