1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-08 14:02:16 +03:00

Modify the sqlite3OsInMutex os-layer interface to take a single parameter

to distinguish between mutexes held by the current thread and mutexes held
by any thread.  Part of the fix for ticket #1630. (CVS 2973)

FossilOrigin-Name: e1ad9df1cf46287f2a7789275e98d28e05880e17
This commit is contained in:
drh
2006-01-18 17:25:45 +00:00
parent 9e12800dec
commit 757b04ed36
7 changed files with 45 additions and 32 deletions

View File

@@ -1,5 +1,5 @@
C Use\sa\sglobal\svariable\sprotected\sby\sa\smutex\sinstead\sof\sthread-specific-data\sto\srecord\smalloc()\sfailures.\s(CVS\s2972) C Modify\sthe\ssqlite3OsInMutex\sos-layer\sinterface\sto\stake\sa\ssingle\sparameter\nto\sdistinguish\sbetween\smutexes\sheld\sby\sthe\scurrent\sthread\sand\smutexes\sheld\nby\sany\sthread.\s\sPart\sof\sthe\sfix\sfor\sticket\s#1630.\s(CVS\s2973)
D 2006-01-18T16:51:35 D 2006-01-18T17:25:46
F Makefile.in ab3ffd8d469cef4477257169b82810030a6bb967 F Makefile.in ab3ffd8d469cef4477257169b82810030a6bb967
F Makefile.linux-gcc aee18d8a05546dcf1888bd4547e442008a49a092 F Makefile.linux-gcc aee18d8a05546dcf1888bd4547e442008a49a092
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -51,15 +51,15 @@ F src/legacy.c 0fd27db5e07a46853b9876baaa370b40e75a9b40
F src/main.c fe0ec40a2cc4d405a6f18884302f61b2b9961351 F src/main.c fe0ec40a2cc4d405a6f18884302f61b2b9961351
F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217 F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
F src/os.c 1d1a61cdf150e9f9520a3bc787c8465148ea2e78 F src/os.c 1d1a61cdf150e9f9520a3bc787c8465148ea2e78
F src/os.h 9debc3d3ca4cdafde222a0ea74a4c8415aef4f22 F src/os.h e4637eadcd5a9ca079029078d31751ae295fb05e
F src/os_common.h 95b29ca6f3e6636cb33c9219b3f91a96fa7224b1 F src/os_common.h 95b29ca6f3e6636cb33c9219b3f91a96fa7224b1
F src/os_test.c 49833426101f99aee4bb5f6a44b7c4b2029fda1c F src/os_test.c 49833426101f99aee4bb5f6a44b7c4b2029fda1c
F src/os_test.h 903c93554c23d88f34f667f1979e4a1cee792af3 F src/os_test.h 903c93554c23d88f34f667f1979e4a1cee792af3
F src/os_unix.c 51fa18a26a390912b02cf3c7c5440bce0893a2cd F src/os_unix.c 9d44bcfbc1e0997331acec827027637dbe9d7131
F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e
F src/os_win.c a1584b153521d2cd46eb7f1ba11e756a158214db F src/os_win.c 98e4e38db7d4a00647b2bb1c60d28b7ca5034c03
F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
F src/pager.c 099b24285de0a649a666e9514d5fd06265cd52cb F src/pager.c 651fda1756c2334009e14bfdc652aadbdbed4e8c
F src/pager.h e0acb095b3ad0bca48f2ab00c87346665643f64f F src/pager.h e0acb095b3ad0bca48f2ab00c87346665643f64f
F src/parse.y 83df51fea35f68f7e07384d75dce83d1ed30434c F src/parse.y 83df51fea35f68f7e07384d75dce83d1ed30434c
F src/pragma.c 4496cc77dc35824e1c978c3d1413b8a5a4c777d3 F src/pragma.c 4496cc77dc35824e1c978c3d1413b8a5a4c777d3
@@ -85,7 +85,7 @@ F src/tokenize.c 1ac078540c2074568e16c0e9beea836fb16b1adc
F src/trigger.c 4d3644cbd16959b568c95ae73493402be8021b08 F src/trigger.c 4d3644cbd16959b568c95ae73493402be8021b08
F src/update.c 14be4ba2f438919b4217085c02feff569e6cf1f2 F src/update.c 14be4ba2f438919b4217085c02feff569e6cf1f2
F src/utf.c 5ab8ca05d4e9ec81174b010f01ab12a232f0087d F src/utf.c 5ab8ca05d4e9ec81174b010f01ab12a232f0087d
F src/util.c be92fe7252c3de3daf5d31f5e092034d722a1b78 F src/util.c b916d21774e6259d86e875df399dbe1a28e69b8e
F src/vacuum.c 3865673cc66acd0717ecd517f6b8fdb2a5e7924b F src/vacuum.c 3865673cc66acd0717ecd517f6b8fdb2a5e7924b
F src/vdbe.c 5af32281e96b2c3e29f50975a86b9f5eef044057 F src/vdbe.c 5af32281e96b2c3e29f50975a86b9f5eef044057
F src/vdbe.h 8729a4ee16ff9aeab2af9667df3cf300ff978e13 F src/vdbe.h 8729a4ee16ff9aeab2af9667df3cf300ff978e13
@@ -341,7 +341,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
P 4de5c52920c94e2a29ef4b68eb8b990c63005b3d P ac090f2ab3b5a792c2fdf897e10060f263e0d408
R 403ff22c240e689bfcaace78e8d9476c R 789c880886342b50e95c468de56aedb9
U danielk1977 U drh
Z ac23f94436e405c8af5dead1d9e7f57e Z cf39b9ccff84563836ed01af4518e925

View File

@@ -1 +1 @@
ac090f2ab3b5a792c2fdf897e10060f263e0d408 e1ad9df1cf46287f2a7789275e98d28e05880e17

View File

@@ -291,7 +291,7 @@ int sqlite3OsSleep(int ms);
int sqlite3OsCurrentTime(double*); int sqlite3OsCurrentTime(double*);
void sqlite3OsEnterMutex(void); void sqlite3OsEnterMutex(void);
void sqlite3OsLeaveMutex(void); void sqlite3OsLeaveMutex(void);
int sqlite3OsInMutex(void); int sqlite3OsInMutex(int);
ThreadData *sqlite3OsThreadSpecificData(int); ThreadData *sqlite3OsThreadSpecificData(int);
void *sqlite3OsMalloc(int); void *sqlite3OsMalloc(int);
void *sqlite3OsRealloc(void *, int); void *sqlite3OsRealloc(void *, int);

View File

@@ -478,7 +478,7 @@ static void testThreadLockingBehavior(fd_orig){
** Release a lockInfo structure previously allocated by findLockInfo(). ** Release a lockInfo structure previously allocated by findLockInfo().
*/ */
static void releaseLockInfo(struct lockInfo *pLock){ static void releaseLockInfo(struct lockInfo *pLock){
assert( sqlite3OsInMutex() ); assert( sqlite3OsInMutex(1) );
pLock->nRef--; pLock->nRef--;
if( pLock->nRef==0 ){ if( pLock->nRef==0 ){
sqlite3HashInsert(&lockHash, &pLock->key, sizeof(pLock->key), 0); sqlite3HashInsert(&lockHash, &pLock->key, sizeof(pLock->key), 0);
@@ -490,7 +490,7 @@ static void releaseLockInfo(struct lockInfo *pLock){
** Release a openCnt structure previously allocated by findLockInfo(). ** Release a openCnt structure previously allocated by findLockInfo().
*/ */
static void releaseOpenCnt(struct openCnt *pOpen){ static void releaseOpenCnt(struct openCnt *pOpen){
assert( sqlite3OsInMutex() ); assert( sqlite3OsInMutex(1) );
pOpen->nRef--; pOpen->nRef--;
if( pOpen->nRef==0 ){ if( pOpen->nRef==0 ){
sqlite3HashInsert(&openHash, &pOpen->key, sizeof(pOpen->key), 0); sqlite3HashInsert(&openHash, &pOpen->key, sizeof(pOpen->key), 0);
@@ -520,7 +520,7 @@ static int findLockInfo(
rc = fstat(fd, &statbuf); rc = fstat(fd, &statbuf);
if( rc!=0 ) return 1; if( rc!=0 ) return 1;
assert( sqlite3OsInMutex() ); assert( sqlite3OsInMutex(1) );
memset(&key1, 0, sizeof(key1)); memset(&key1, 0, sizeof(key1));
key1.dev = statbuf.st_dev; key1.dev = statbuf.st_dev;
key1.ino = statbuf.st_ino; key1.ino = statbuf.st_ino;
@@ -1680,7 +1680,7 @@ static pthread_mutex_t mutex2 = PTHREAD_MUTEX_INITIALIZER;
** SQLite uses only a single Mutex. There is not much critical ** SQLite uses only a single Mutex. There is not much critical
** code and what little there is executes quickly and without blocking. ** code and what little there is executes quickly and without blocking.
** **
** This mutex is not recursive. ** As of version 3.3.2, this mutex must be recursive.
*/ */
void sqlite3UnixEnterMutex(){ void sqlite3UnixEnterMutex(){
#ifdef SQLITE_UNIX_THREADS #ifdef SQLITE_UNIX_THREADS
@@ -1709,13 +1709,18 @@ void sqlite3UnixLeaveMutex(){
} }
/* /*
** Return TRUE if we are currently within the mutex and FALSE if not. ** Return TRUE if the mutex is currently held.
**
** If the thisThreadOnly parameter is true, return true only if the
** calling thread holds the mutex. If the parameter is false, return
** true if any thread holds the mutex.
*/ */
int sqlite3UnixInMutex(){ int sqlite3UnixInMutex(int thisThreadOnly){
#ifdef SQLITE_UNIX_THREADS #ifdef SQLITE_UNIX_THREADS
return inMutex && pthread_equal(mutexOwner, pthread_self()); return inMutex>0 &&
(thisThreadOnly==0 || pthread_equal(mutexOwner, pthread_self()));
#else #else
return inMutex; return inMutex>0;
#endif #endif
} }

View File

@@ -1068,17 +1068,20 @@ int sqlite3WinSleep(int ms){
*/ */
static int inMutex = 0; static int inMutex = 0;
#ifdef SQLITE_W32_THREADS #ifdef SQLITE_W32_THREADS
static HANDLE mutexOwner; static DWORD mutexOwner;
static CRITICAL_SECTION cs; static CRITICAL_SECTION cs;
#endif #endif
/* /*
** The following pair of routine implement mutual exclusion for ** The following pair of routines implement mutual exclusion for
** multi-threaded processes. Only a single thread is allowed to ** multi-threaded processes. Only a single thread is allowed to
** executed code that is surrounded by EnterMutex() and LeaveMutex(). ** executed code that is surrounded by EnterMutex() and LeaveMutex().
** **
** SQLite uses only a single Mutex. There is not much critical ** SQLite uses only a single Mutex. There is not much critical
** code and what little there is executes quickly and without blocking. ** code and what little there is executes quickly and without blocking.
**
** Version 3.3.1 and earlier used a simple mutex. Beginning with
** version 3.3.2, a recursive mutex is required.
*/ */
void sqlite3WinEnterMutex(){ void sqlite3WinEnterMutex(){
#ifdef SQLITE_W32_THREADS #ifdef SQLITE_W32_THREADS
@@ -1093,7 +1096,7 @@ void sqlite3WinEnterMutex(){
} }
} }
EnterCriticalSection(&cs); EnterCriticalSection(&cs);
mutexOwner = GetCurrentThread(); mutexOwner = GetCurrentThreadId();
#endif #endif
inMutex++; inMutex++;
} }
@@ -1101,18 +1104,23 @@ void sqlite3WinLeaveMutex(){
assert( inMutex ); assert( inMutex );
inMutex--; inMutex--;
#ifdef SQLITE_W32_THREADS #ifdef SQLITE_W32_THREADS
assert( mutexOwner==GetCurrentThreadId() );
LeaveCriticalSection(&cs); LeaveCriticalSection(&cs);
#endif #endif
} }
/* /*
** Return TRUE if we are currently within the mutex and FALSE if not. ** Return TRUE if the mutex is currently held.
**
** If the thisThreadOnly parameter is true, return true if and only if the
** calling thread holds the mutex. If the parameter is false, return
** true if any thread holds the mutex.
*/ */
int sqlite3WinInMutex(){ int sqlite3WinInMutex(int thisThreadOnly){
#ifdef SQLITE_W32_THREADS #ifdef SQLITE_W32_THREADS
return inMutex && mutexOwner==GetCurrentThread(); return inMutex>0 && (thisThreadOnly==0 || mutexOwner==GetCurrentThreadId());
#else #else
return inMutex; return inMutex>0;
#endif #endif
} }

View File

@@ -18,7 +18,7 @@
** file simultaneously, or one process from reading the database while ** file simultaneously, or one process from reading the database while
** another is writing. ** another is writing.
** **
** @(#) $Id: pager.c,v 1.243 2006/01/18 16:51:35 danielk1977 Exp $ ** @(#) $Id: pager.c,v 1.244 2006/01/18 17:25:46 drh Exp $
*/ */
#ifndef SQLITE_OMIT_DISKIO #ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h" #include "sqliteInt.h"
@@ -2437,7 +2437,7 @@ int sqlite3pager_release_memory(int nReq){
** some of the code invoked by this function may also ** some of the code invoked by this function may also
** try to obtain the mutex, resulting in a deadlock. ** try to obtain the mutex, resulting in a deadlock.
*/ */
if( sqlite3OsInMutex() ){ if( sqlite3OsInMutex(0) ){
return 0; return 0;
} }

View File

@@ -14,7 +14,7 @@
** This file contains functions for allocating memory, comparing ** This file contains functions for allocating memory, comparing
** strings, and stuff like that. ** strings, and stuff like that.
** **
** $Id: util.c,v 1.176 2006/01/18 16:51:36 danielk1977 Exp $ ** $Id: util.c,v 1.177 2006/01/18 17:25:46 drh Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include "os.h" #include "os.h"
@@ -1373,7 +1373,7 @@ int sqlite3ApiExit(sqlite3* db, int rc){
** to sqlite3ApiExit(), or false otherwise. ** to sqlite3ApiExit(), or false otherwise.
*/ */
int sqlite3MallocFailed(){ int sqlite3MallocFailed(){
return (mallocHasFailed && sqlite3OsInMutex()); return (mallocHasFailed && sqlite3OsInMutex(1));
} }
/* /*