aboutsummaryrefslogtreecommitdiff
path: root/src/mutex_unix.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2007-11-28 13:55:55 +0000
committerdrh <drh@noemail.net>2007-11-28 13:55:55 +0000
commit5f3d652394e03d3f39fe2cbcc04ad399d192901a (patch)
tree1dc7f1d36c9442bb182a81a8bf4d4384e40970a3 /src/mutex_unix.c
parent4aa2bfe67d0989c17c2d2494109035d486a0053a (diff)
downloadsqlite-5f3d652394e03d3f39fe2cbcc04ad399d192901a.tar.gz
sqlite-5f3d652394e03d3f39fe2cbcc04ad399d192901a.zip
Clarify the conditions under which homegrown recursive mutexes work
(they require a coherent cache) and only enable them if there is an explicit #define so as to avoid accidental use on platforms that do not meet the constraints. Ticket #2805. (CVS 4575) FossilOrigin-Name: 80299eebddba9aac4c1bc36ffa2b440bffbf1751
Diffstat (limited to 'src/mutex_unix.c')
-rw-r--r--src/mutex_unix.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/mutex_unix.c b/src/mutex_unix.c
index 20a4e0ea7..4b7971bc8 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.3 2007/11/28 00:51:35 drh Exp $
+** $Id: mutex_unix.c,v 1.4 2007/11/28 13:55:55 drh Exp $
*/
#include "sqliteInt.h"
@@ -94,7 +94,7 @@ sqlite3_mutex *sqlite3_mutex_alloc(int iType){
case SQLITE_MUTEX_RECURSIVE: {
p = sqlite3MallocZero( sizeof(*p) );
if( p ){
-#ifdef PTHREAD_MUTEX_RECURSIVE
+#ifndef SQLITE_HOMEGROWN_RECURSIVE_MUTEX
/* Use a recursive mutex if it is available */
pthread_mutexattr_t recursiveAttr;
pthread_mutexattr_init(&recursiveAttr);
@@ -158,9 +158,8 @@ void sqlite3_mutex_enter(sqlite3_mutex *p){
assert( p );
assert( p->id==SQLITE_MUTEX_RECURSIVE || sqlite3_mutex_notheld(p) );
-#ifdef PTHREAD_MUTEX_RECURSIVE
+#ifndef SQLITE_HOMEGROWN_RECURSIVE_MUTEX
/* Use the built-in recursive mutexes if they are available.
- ** That they are not available on all systems.
*/
pthread_mutex_lock(&p->mutex);
p->owner = pthread_self();
@@ -171,6 +170,10 @@ void sqlite3_mutex_enter(sqlite3_mutex *p){
** is atomic - that it cannot be deceived into thinking self
** and p->owner are equal if p->owner changes between two values
** that are not equal to self while the comparison is taking place.
+ ** This implementation also assumes a coherent cache - that
+ ** separate processes cannot read different values from the same
+ ** address at the same time. If either of these two conditions
+ ** are not met, then the mutexes will fail and problems will result.
*/
{
pthread_t self = pthread_self();
@@ -196,9 +199,8 @@ int sqlite3_mutex_try(sqlite3_mutex *p){
assert( p );
assert( p->id==SQLITE_MUTEX_RECURSIVE || sqlite3_mutex_notheld(p) );
-#ifdef PTHREAD_MUTEX_RECURSIVE
+#ifndef SQLITE_HOMEGROWN_RECURSIVE_MUTEX
/* Use the built-in recursive mutexes if they are available.
- ** That they are not available on all systems.
*/
if( pthread_mutex_trylock(&p->mutex)==0 ){
p->owner = pthread_self();
@@ -213,6 +215,10 @@ int sqlite3_mutex_try(sqlite3_mutex *p){
** is atomic - that it cannot be deceived into thinking self
** and p->owner are equal if p->owner changes between two values
** that are not equal to self while the comparison is taking place.
+ ** This implementation also assumes a coherent cache - that
+ ** separate processes cannot read different values from the same
+ ** address at the same time. If either of these two conditions
+ ** are not met, then the mutexes will fail and problems will result.
*/
{
pthread_t self = pthread_self();