From: mistachkin Date: Mon, 17 Oct 2016 18:59:52 +0000 (+0000) Subject: Enhancments to Win32 mutex debugging. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=80e8ff03359b68ed7fe052d1ca3452e2fd865afc;p=thirdparty%2Fsqlite.git Enhancments to Win32 mutex debugging. FossilOrigin-Name: 2fb9a5dd40662b6d3c7dfa4cdac47cb2401a289e --- diff --git a/manifest b/manifest index 5656b11205..e9756d51a0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Version\s3.14.2 -D 2016-09-12T18:50:49.277 +C Enhancments\sto\sWin32\smutex\sdebugging. +D 2016-10-17T18:59:52.378 F Makefile.in cfd8fb987cd7a6af046daa87daa146d5aad0e088 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 6fef1e10792656c94fe1393092de6c8ba6ea1c88 @@ -358,10 +358,10 @@ F src/mem5.c 9bf955937b07f8c32541c8a9991f33ce3173d944 F src/memjournal.c 95752936c11dc6995672d1dd783cd633eea0cc95 F src/msvc.h 4942752b6a253116baaa8de75256c51a459a5e81 F src/mutex.c 8e45800ee78e0cd1f1f3fe8e398853307f4a085c -F src/mutex.h 779d588e3b7756ec3ecf7d78cde1d84aba414f85 +F src/mutex.h ab41f241d91ca195c2fb226b245c96da051a93dc F src/mutex_noop.c 9d4309c075ba9cc7249e19412d3d62f7f94839c4 F src/mutex_unix.c 27bb6cc49485ee46711a6580ab7b3f1402211d23 -F src/mutex_w32.c 5e6fe1c298fb5a8a15aaed4161d5759311431c17 +F src/mutex_w32.c 02e4d0d55ac9bafdbb1df1a6c9d1fee180abc57e F src/notify.c 9711a7575036f0d3040ba61bc6e217f13a9888e7 F src/os.c add02933b1dce7a39a005b00a2f5364b763e9a24 F src/os.h 8e976e59eb4ca1c0fca6d35ee803e38951cb0343 @@ -1509,10 +1509,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P a04a21ad5aa1a56d50388d6cdb88bae754218a0a -R 073817cadc2d2cf4f1a705c7b7ab3a16 -T +bgcolor * #d0c0ff -T +sym-release * -T +sym-version-3.14.2 * -U drh -Z 3b9eb30be1058877308d90519a39b4b7 +P 29dbef4b8585f753861a36d6dd102ca634197bd6 +R 8e951a50bfdf4d021638237d1f4f6237 +T *branch * mutexDbg +T *sym-mutexDbg * +T -sym-branch-3.14 * +U mistachkin +Z 74809fa8d266455b16cda282d92b2f04 diff --git a/manifest.uuid b/manifest.uuid index 7d599e6511..41849ece33 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -29dbef4b8585f753861a36d6dd102ca634197bd6 \ No newline at end of file +2fb9a5dd40662b6d3c7dfa4cdac47cb2401a289e \ No newline at end of file diff --git a/src/mutex.h b/src/mutex.h index 03eb1faadb..e21d92dad5 100644 --- a/src/mutex.h +++ b/src/mutex.h @@ -50,6 +50,13 @@ # endif #endif +/* +** Allowed values for sqlite3_mutex.magic +*/ +#define SQLITE_MUTEXMAGIC_NORMAL 0x1f7a8074 +#define SQLITE_MUTEXMAGIC_TRACE 0x1f7a8075 +#define SQLITE_MUTEXMAGIC_DEAD 0x4b0844f6 + #ifdef SQLITE_MUTEX_OMIT /* ** If this is a no-op implementation, implement everything as macros. diff --git a/src/mutex_w32.c b/src/mutex_w32.c index 9570bdc0bf..420db05bef 100644 --- a/src/mutex_w32.c +++ b/src/mutex_w32.c @@ -40,7 +40,7 @@ struct sqlite3_mutex { #ifdef SQLITE_DEBUG volatile int nRef; /* Number of enterances */ volatile DWORD owner; /* Thread holding this mutex */ - volatile int trace; /* True to trace changes */ + volatile u32 magic; /* True to trace changes */ #endif }; @@ -221,7 +221,9 @@ static sqlite3_mutex *winMutexAlloc(int iType){ p->id = iType; #ifdef SQLITE_DEBUG #ifdef SQLITE_WIN32_MUTEX_TRACE_DYNAMIC - p->trace = 1; + p->magic = SQLITE_MUTEXMAGIC_TRACE; +#else + p->magic = SQLITE_MUTEXMAGIC_NORMAL; #endif #endif #if SQLITE_OS_WINRT @@ -243,7 +245,9 @@ static sqlite3_mutex *winMutexAlloc(int iType){ p->id = iType; #ifdef SQLITE_DEBUG #ifdef SQLITE_WIN32_MUTEX_TRACE_STATIC - p->trace = 1; + p->magic = SQLITE_MUTEXMAGIC_TRACE; +#else + p->magic = SQLITE_MUTEXMAGIC_NORMAL; #endif #endif break; @@ -260,6 +264,7 @@ static sqlite3_mutex *winMutexAlloc(int iType){ */ static void winMutexFree(sqlite3_mutex *p){ assert( p ); + assert( (p->magic&~1)==SQLITE_MUTEXMAGIC_NORMAL ); assert( p->nRef==0 && p->owner==0 ); if( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE ){ DeleteCriticalSection(&p->mutex); @@ -286,11 +291,10 @@ static void winMutexEnter(sqlite3_mutex *p){ #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) DWORD tid = GetCurrentThreadId(); #endif -#ifdef SQLITE_DEBUG assert( p ); + assert( (p->magic&~1)==SQLITE_MUTEXMAGIC_NORMAL ); +#ifdef SQLITE_DEBUG assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld2(p, tid) ); -#else - assert( p ); #endif assert( winMutex_isInit==1 ); EnterCriticalSection(&p->mutex); @@ -298,9 +302,9 @@ static void winMutexEnter(sqlite3_mutex *p){ assert( p->nRef>0 || p->owner==0 ); p->owner = tid; p->nRef++; - if( p->trace ){ - OSTRACE(("ENTER-MUTEX tid=%lu, mutex=%p (%d), nRef=%d\n", - tid, p, p->trace, p->nRef)); + if( p->magic&1 ){ + OSTRACE(("ENTER-MUTEX tid=%lu, mutex=%p (%lu), nRef=%d\n", + tid, p, p->magic, p->nRef)); } #endif } @@ -311,7 +315,10 @@ static int winMutexTry(sqlite3_mutex *p){ #endif int rc = SQLITE_BUSY; assert( p ); + assert( (p->magic&~1)==SQLITE_MUTEXMAGIC_NORMAL ); +#ifdef SQLITE_DEBUG assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld2(p, tid) ); +#endif /* ** 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 @@ -341,9 +348,9 @@ static int winMutexTry(sqlite3_mutex *p){ UNUSED_PARAMETER(p); #endif #ifdef SQLITE_DEBUG - if( p->trace ){ - OSTRACE(("TRY-MUTEX tid=%lu, mutex=%p (%d), owner=%lu, nRef=%d, rc=%s\n", - tid, p, p->trace, p->owner, p->nRef, sqlite3ErrName(rc))); + if( p->magic&1 ){ + OSTRACE(("TRY-MUTEX tid=%lu, mutex=%p (%lu), owner=%lu, nRef=%d, rc=%s\n", + tid, p, p->magic, p->owner, p->nRef, sqlite3ErrName(rc))); } #endif return rc; @@ -360,6 +367,7 @@ static void winMutexLeave(sqlite3_mutex *p){ DWORD tid = GetCurrentThreadId(); #endif assert( p ); + assert( (p->magic&~1)==SQLITE_MUTEXMAGIC_NORMAL ); #ifdef SQLITE_DEBUG assert( p->nRef>0 ); assert( p->owner==tid ); @@ -370,9 +378,9 @@ static void winMutexLeave(sqlite3_mutex *p){ assert( winMutex_isInit==1 ); LeaveCriticalSection(&p->mutex); #ifdef SQLITE_DEBUG - if( p->trace ){ - OSTRACE(("LEAVE-MUTEX tid=%lu, mutex=%p (%d), nRef=%d\n", - tid, p, p->trace, p->nRef)); + if( p->magic&1 ){ + OSTRACE(("LEAVE-MUTEX tid=%lu, mutex=%p (%lu), nRef=%d\n", + tid, p, p->magic, p->nRef)); } #endif }