/ Check-in [04cafb7e]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fixed "Interlocked" logic error that prevented the "static" mutexes from being released when sqlite3_shutdown() is called. Ticket #4011. (CVS 6964)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 04cafb7ee3b67a68c0604d7f1143feaec44be610
User & Date: shane 2009-08-10 03:23:21
Context
2009-08-10
03:57
Removed some warnings from the MSVC compile. (CVS 6965) check-in: ee034cfc user: shane tags: trunk
03:23
Fixed "Interlocked" logic error that prevented the "static" mutexes from being released when sqlite3_shutdown() is called. Ticket #4011. (CVS 6964) check-in: 04cafb7e user: shane tags: trunk
2009-08-08
18:01
Suppress various compiler warnings. (CVS 6963) check-in: 257e9b57 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/mutex_w32.c.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains the C functions that implement mutexes for win32
    13     13   **
    14         -** $Id: mutex_w32.c,v 1.17 2009/06/01 17:10:22 shane Exp $
           14  +** $Id: mutex_w32.c,v 1.18 2009/08/10 03:23:21 shane Exp $
    15     15   */
    16     16   #include "sqliteInt.h"
    17     17   
    18     18   /*
    19     19   ** The code in this file is only used if we are compiling multithreaded
    20     20   ** on a win32 system.
    21     21   */
................................................................................
    89     89   ** processing, the "interlocked" magic is probably not
    90     90   ** strictly necessary.
    91     91   */
    92     92   static long winMutex_lock = 0;
    93     93   
    94     94   static int winMutexInit(void){ 
    95     95     /* The first to increment to 1 does actual initialization */
    96         -  if( InterlockedIncrement(&winMutex_lock)==1 ){
           96  +  if( InterlockedCompareExchange(&winMutex_lock, 1, 0)==0 ){
    97     97       int i;
    98     98       for(i=0; i<sizeof(winMutex_staticMutexes)/sizeof(winMutex_staticMutexes[0]); i++){
    99     99         InitializeCriticalSection(&winMutex_staticMutexes[i].mutex);
   100    100       }
   101    101       winMutex_isInit = 1;
   102    102     }else{
          103  +    /* Someone else is in the process of initing the static mutexes */
   103    104       while( !winMutex_isInit ){
   104    105         Sleep(1);
   105    106       }
   106    107     }
   107    108     return SQLITE_OK; 
   108    109   }
   109    110   
   110    111   static int winMutexEnd(void){ 
   111    112     /* The first to decrement to 0 does actual shutdown 
   112    113     ** (which should be the last to shutdown.) */
   113         -  if( InterlockedDecrement(&winMutex_lock)==0 ){
          114  +  if( InterlockedCompareExchange(&winMutex_lock, 0, 1)==1 ){
   114    115       if( winMutex_isInit==1 ){
   115    116         int i;
   116    117         for(i=0; i<sizeof(winMutex_staticMutexes)/sizeof(winMutex_staticMutexes[0]); i++){
   117    118           DeleteCriticalSection(&winMutex_staticMutexes[i].mutex);
   118    119         }
   119    120         winMutex_isInit = 0;
   120    121       }