From: shaneh Date: Sat, 13 Feb 2010 02:31:09 +0000 (+0000) Subject: Merged tracing and initialization changes from mutex_unix.c. X-Git-Tag: version-3.7.2~613 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1f4222f84c4303a7ec06184dbf1e282e08815680;p=thirdparty%2Fsqlite.git Merged tracing and initialization changes from mutex_unix.c. FossilOrigin-Name: 942aa1f6a91655356cc32a8185cb447331d405dc --- diff --git a/manifest b/manifest index b55b24d0ab..e12c1afa2b 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,5 @@ ------BEGIN PGP SIGNED MESSAGE----- -Hash: SHA1 - -C Enhancements\sto\sthe\ssecure_delete\spragma\sto\smake\sit\seasier\sto\suse. -D 2010-02-12T19:46:27 +C Merged\stracing\sand\sinitialization\schanges\sfrom\smutex_unix.c. +D 2010-02-13T02:31:09 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in c5827ead754ab32b9585487177c93bb00b9497b3 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -145,7 +142,7 @@ F src/mutex.h 6fde601e55fa6c3fae768783c439797ab84c87c6 F src/mutex_noop.c 5f58eaa31f2d742cb8957a747f7887ae98f16053 F src/mutex_os2.c 20477db50cf3817c2f1cd3eb61e5c177e50231db F src/mutex_unix.c 04a25238abce7e3d06b358dcf706e26624270809 -F src/mutex_w32.c 9ec75bcef0ca722821be7968c320fd725abfb984 +F src/mutex_w32.c 90c3bd10db9f2c30b1f24a1885b54a8a263ff86a F src/notify.c f799bbda67ab6619b36b0a24153b49518874a203 F src/os.c 8bc63cf91e9802e2b807198e54e50227fa889306 F src/os.h 534b082c3cb349ad05fa6fa0b06087e022af282c @@ -790,14 +787,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P f72f8a870a0fc98a9f2b564ffafe7946bbce506e -R b61a1284585a029b8ec102ac4156fb15 -U drh -Z d9b19f603d580b3226157728109cbbd5 ------BEGIN PGP SIGNATURE----- -Version: GnuPG v1.4.6 (GNU/Linux) - -iD8DBQFLdbAVoxKgR168RlERAj5YAJ42YouMVbChw0/Wmuc1J2A6U9XZigCeJm/S -8JFH6+GHy+lsobZdTvVyj/I= -=Aq2n ------END PGP SIGNATURE----- +P 2bb38bb96ff6b9fb91dd1cf214041cf113ac5508 +R 232b63cb29b9e4506009aea6dd09a4d6 +U shaneh +Z 85585006145b2cc2993f7e2137036d14 diff --git a/manifest.uuid b/manifest.uuid index a314500523..4d742758ea 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2bb38bb96ff6b9fb91dd1cf214041cf113ac5508 \ No newline at end of file +942aa1f6a91655356cc32a8185cb447331d405dc \ No newline at end of file diff --git a/src/mutex_w32.c b/src/mutex_w32.c index 181f82122c..5abe82106e 100644 --- a/src/mutex_w32.c +++ b/src/mutex_w32.c @@ -27,7 +27,16 @@ struct sqlite3_mutex { int id; /* Mutex type */ int nRef; /* Number of enterances */ DWORD owner; /* Thread holding this mutex */ +#ifdef SQLITE_DEBUG + int trace; /* True to trace changes */ +#endif }; +#define SQLITE_W32_MUTEX_INITIALIZER { 0 } +#ifdef SQLITE_DEBUG +#define SQLITE3_MUTEX_INITIALIZER { SQLITE_W32_MUTEX_INITIALIZER, 0, 0L, (DWORD)0, 0 } +#else +#define SQLITE3_MUTEX_INITIALIZER { SQLITE_W32_MUTEX_INITIALIZER, 0, 0L, (DWORD)0 } +#endif /* ** Return true (non-zero) if we are running under WinNT, Win2K, WinXP, @@ -71,8 +80,12 @@ struct sqlite3_mutex { static int winMutexHeld(sqlite3_mutex *p){ return p->nRef!=0 && p->owner==GetCurrentThreadId(); } +static int winMutexNotheld2(sqlite3_mutex *p, DWORD tid){ + return p->nRef==0 || p->owner!=tid; +} static int winMutexNotheld(sqlite3_mutex *p){ - return p->nRef==0 || p->owner!=GetCurrentThreadId(); + DWORD tid = GetCurrentThreadId(); + return winMutexNotheld2(p, tid); } #endif @@ -80,7 +93,14 @@ static int winMutexNotheld(sqlite3_mutex *p){ /* ** Initialize and deinitialize the mutex subsystem. */ -static sqlite3_mutex winMutex_staticMutexes[6]; +static sqlite3_mutex winMutex_staticMutexes[6] = { + SQLITE3_MUTEX_INITIALIZER, + SQLITE3_MUTEX_INITIALIZER, + SQLITE3_MUTEX_INITIALIZER, + SQLITE3_MUTEX_INITIALIZER, + SQLITE3_MUTEX_INITIALIZER, + SQLITE3_MUTEX_INITIALIZER +}; static int winMutex_isInit = 0; /* As winMutexInit() and winMutexEnd() are called as part ** of the sqlite3_initialize and sqlite3_shutdown() @@ -214,14 +234,21 @@ static void winMutexFree(sqlite3_mutex *p){ ** more than once, the behavior is undefined. */ static void winMutexEnter(sqlite3_mutex *p){ - assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld(p) ); + DWORD tid = GetCurrentThreadId(); + assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld2(p, tid) ); EnterCriticalSection(&p->mutex); - p->owner = GetCurrentThreadId(); + p->owner = tid; p->nRef++; +#ifdef SQLITE_DEBUG + if( p->trace ){ + printf("enter mutex %p (%d) with nRef=%d\n", p, p->trace, p->nRef); + } +#endif } static int winMutexTry(sqlite3_mutex *p){ + DWORD tid = GetCurrentThreadId(); int rc = SQLITE_BUSY; - assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld(p) ); + assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld2(p, tid) ); /* ** The sqlite3_mutex_try() routine is very rarely used, and when it ** is used it is merely an optimization. So it is OK for it to always @@ -235,12 +262,17 @@ static int winMutexTry(sqlite3_mutex *p){ */ #if 0 if( mutexIsNT() && TryEnterCriticalSection(&p->mutex) ){ - p->owner = GetCurrentThreadId(); + p->owner = tid; p->nRef++; rc = SQLITE_OK; } #else UNUSED_PARAMETER(p); +#endif +#ifdef SQLITE_DEBUG + if( rc==SQLITE_OK && p->trace ){ + printf("enter mutex %p (%d) with nRef=%d\n", p, p->trace, p->nRef); + } #endif return rc; } @@ -252,11 +284,17 @@ static int winMutexTry(sqlite3_mutex *p){ ** is not currently allocated. SQLite will never do either. */ static void winMutexLeave(sqlite3_mutex *p){ + DWORD tid = GetCurrentThreadId(); assert( p->nRef>0 ); - assert( p->owner==GetCurrentThreadId() ); + assert( p->owner==tid ); p->nRef--; assert( p->nRef==0 || p->id==SQLITE_MUTEX_RECURSIVE ); LeaveCriticalSection(&p->mutex); +#ifdef SQLITE_DEBUG + if( p->trace ){ + printf("leave mutex %p (%d) with nRef=%d\n", p, p->trace, p->nRef); + } +#endif } sqlite3_mutex_methods *sqlite3DefaultMutex(void){