aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--manifest12
-rw-r--r--manifest.uuid2
-rw-r--r--src/mutex_w32.c63
3 files changed, 50 insertions, 27 deletions
diff --git a/manifest b/manifest
index 44ba393e4..9b5add9e6 100644
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\scompiler\swarnings\swith\sMSVC\sbuild.\s(CVS\s6699)
-D 2009-06-01T16:53:10
+C Ensure\sthat\s"static"\smutexes\sare\sdeleted\son\sshutdown\sso\sthat\sthey\sare\snot\sleaked\sacross\srestarts.\s(CVS\s6700)
+D 2009-06-01T17:06:08
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 583e87706abc3026960ed759aff6371faf84c211
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -138,7 +138,7 @@ F src/mutex.h 9e686e83a88838dac8b9c51271c651e833060f1e
F src/mutex_noop.c f5a07671f25a1a9bd7c10ad7107bc2585446200f
F src/mutex_os2.c 6b5a74f812082a8483c3df05b47bbaac2424b9a0
F src/mutex_unix.c 2f936339dfef1a4c142db290d575a3509b77315f
-F src/mutex_w32.c f4b6a4a48f1dfff7f0089cba9b5a371691f17b8b
+F src/mutex_w32.c 3dd7c4fd63546c4e1fe71a69a45ec37b74654843
F src/notify.c 0127121816d8a861deb0dfd111b495346bf233db
F src/os.c c2aa4a7d8bb845222e5c37f56cde377b20c3b087
F src/os.h fa3f4aa0119ff721a2da4b47ffd74406ac864c05
@@ -731,7 +731,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P 0f6bc5e1ba6937b36df08ed3b5903839389021bb
-R 16e1f2d594599a039f283a098ab59d1c
+P 0791588520603d106aa0b8ce24d68b740b7b80c8
+R 8cd431ad0020e4aa3530ef419536d17a
U shane
-Z 5685cf42211f0e6a13fdf03ca05f0474
+Z e7a4fe02802663fd359b8200de1cba6f
diff --git a/manifest.uuid b/manifest.uuid
index 52f3ec49f..31aaf47d8 100644
--- a/manifest.uuid
+++ b/manifest.uuid
@@ -1 +1 @@
-0791588520603d106aa0b8ce24d68b740b7b80c8 \ No newline at end of file
+4e75897ee177bd24145f9dbfccd41a03c108440f \ No newline at end of file
diff --git a/src/mutex_w32.c b/src/mutex_w32.c
index eeb2d798f..a7115b84c 100644
--- a/src/mutex_w32.c
+++ b/src/mutex_w32.c
@@ -11,7 +11,7 @@
*************************************************************************
** This file contains the C functions that implement mutexes for win32
**
-** $Id: mutex_w32.c,v 1.15 2009/01/30 16:09:23 shane Exp $
+** $Id: mutex_w32.c,v 1.16 2009/06/01 17:06:08 shane Exp $
*/
#include "sqliteInt.h"
@@ -82,8 +82,45 @@ static int winMutexNotheld(sqlite3_mutex *p){
/*
** Initialize and deinitialize the mutex subsystem.
*/
-static int winMutexInit(void){ return SQLITE_OK; }
-static int winMutexEnd(void){ return SQLITE_OK; }
+static sqlite3_mutex winMutex_staticMutexes[6];
+static int winMutex_isInit = 0;
+/* As winMutexInit() and winMutexEnd() are called as part
+** of the sqlite3_initialize and sqlite3_shutdown()
+** processing, the "interlocked" magic is probably not
+** strictly necessary.
+*/
+static long winMutex_lock = 0;
+
+static int winMutexInit(void){
+ /* The first to increment to 1 does actual initialization */
+ if( InterlockedIncrement(&winMutex_lock)==1 ){
+ int i;
+ for(i=0; i<sizeof(winMutex_staticMutexes)/sizeof(winMutex_staticMutexes[0]); i++){
+ InitializeCriticalSection(&winMutex_staticMutexes[i].mutex);
+ }
+ winMutex_isInit = 1;
+ }else{
+ while( !winMutex_isInit ){
+ Sleep(1);
+ }
+ }
+ return SQLITE_OK;
+}
+
+static int winMutexEnd(void){
+ /* The first to decrement to 0 does actual shutdown
+ ** (which should be the last to shutdown.) */
+ if( InterlockedDecrement(&winMutex_lock)==0 ){
+ if( winMutex_isInit==1 ){
+ int i;
+ for(i=0; i<sizeof(winMutex_staticMutexes)/sizeof(winMutex_staticMutexes[0]); i++){
+ DeleteCriticalSection(&winMutex_staticMutexes[i].mutex);
+ }
+ winMutex_isInit = 0;
+ }
+ }
+ return SQLITE_OK;
+}
/*
** The sqlite3_mutex_alloc() routine allocates a new
@@ -131,30 +168,16 @@ static sqlite3_mutex *winMutexAlloc(int iType){
case SQLITE_MUTEX_FAST:
case SQLITE_MUTEX_RECURSIVE: {
p = sqlite3MallocZero( sizeof(*p) );
- if( p ){
+ if( p ){
p->id = iType;
InitializeCriticalSection(&p->mutex);
}
break;
}
default: {
- static sqlite3_mutex staticMutexes[6];
- static int isInit = 0;
- while( !isInit ){
- static long lock = 0;
- if( InterlockedIncrement(&lock)==1 ){
- int i;
- for(i=0; i<sizeof(staticMutexes)/sizeof(staticMutexes[0]); i++){
- InitializeCriticalSection(&staticMutexes[i].mutex);
- }
- isInit = 1;
- }else{
- Sleep(1);
- }
- }
assert( iType-2 >= 0 );
- assert( iType-2 < sizeof(staticMutexes)/sizeof(staticMutexes[0]) );
- p = &staticMutexes[iType-2];
+ assert( iType-2 < sizeof(winMutex_staticMutexes)/sizeof(winMutex_staticMutexes[0]) );
+ p = &winMutex_staticMutexes[iType-2];
p->id = iType;
break;
}