aboutsummaryrefslogtreecommitdiff
path: root/src/mutex_unix.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2007-08-28 22:24:34 +0000
committerdrh <drh@noemail.net>2007-08-28 22:24:34 +0000
commitd0679edc7a9a41b43ad2984be17a10046b1516c9 (patch)
tree9b6f17d0d579638fff5f5a4c0b3204c2ec40826f /src/mutex_unix.c
parent27a770e044318084cb9640315d83a20bd34d4106 (diff)
downloadsqlite-d0679edc7a9a41b43ad2984be17a10046b1516c9.tar.gz
sqlite-d0679edc7a9a41b43ad2984be17a10046b1516c9.zip
Clean up the locking in the btree logic. (CVS 4316)
FossilOrigin-Name: 967ab229af462a8ae663090ea36b4cc10e351653
Diffstat (limited to 'src/mutex_unix.c')
-rw-r--r--src/mutex_unix.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/mutex_unix.c b/src/mutex_unix.c
index 287a173c5..ff088fb53 100644
--- a/src/mutex_unix.c
+++ b/src/mutex_unix.c
@@ -11,7 +11,7 @@
*************************************************************************
** This file contains the C functions that implement mutexes for pthreads
**
-** $Id: mutex_unix.c,v 1.1 2007/08/28 16:34:43 drh Exp $
+** $Id: mutex_unix.c,v 1.2 2007/08/28 22:24:35 drh Exp $
*/
#include "sqliteInt.h"
@@ -34,6 +34,9 @@ struct sqlite3_mutex {
int id; /* Mutex type */
int nRef; /* Number of entrances */
pthread_t owner; /* Thread that is within this mutex */
+#ifdef SQLITE_DEBUG
+ int trace; /* True to trace changes */
+#endif
};
/*
@@ -149,6 +152,11 @@ void sqlite3_mutex_enter(sqlite3_mutex *p){
pthread_mutex_lock(&p->mutex);
p->owner = pthread_self();
p->nRef++;
+#ifdef SQLITE_DEBUG
+ if( p->trace ){
+ printf("enter mutex %p (%d) with nRef=%d\n", p, p->trace, p->nRef);
+ }
+#endif
}
int sqlite3_mutex_try(sqlite3_mutex *p){
int rc;
@@ -158,6 +166,11 @@ int sqlite3_mutex_try(sqlite3_mutex *p){
p->owner = pthread_self();
p->nRef++;
rc = SQLITE_OK;
+#ifdef SQLITE_DEBUG
+ if( p->trace ){
+ printf("enter mutex %p (%d) with nRef=%d\n", p, p->trace, p->nRef);
+ }
+#endif
}else{
rc = SQLITE_BUSY;
}
@@ -175,6 +188,11 @@ void sqlite3_mutex_leave(sqlite3_mutex *p){
assert( sqlite3_mutex_held(p) );
p->nRef--;
assert( p->nRef==0 || p->id==SQLITE_MUTEX_RECURSIVE );
+#ifdef SQLITE_DEBUG
+ if( p->trace ){
+ printf("leave mutex %p (%d) with nRef=%d\n", p, p->trace, p->nRef);
+ }
+#endif
pthread_mutex_unlock(&p->mutex);
}