/ Check-in [7562f1fb]
Login

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

Overview
Comment:Add more asserts to the mutex subsystem.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | mutexInitCmpSwap
Files: files | file ages | folders
SHA1: 7562f1fbede70b19bbbb928e0a534203528b5b65
User & Date: mistachkin 2015-09-12 03:35:55
Context
2015-09-12
03:40
Clarify the new mutex implementation reset logic in sqlite3_shutdown(). check-in: f9a03483 user: mistachkin tags: mutexInitCmpSwap
03:35
Add more asserts to the mutex subsystem. check-in: 7562f1fb user: mistachkin tags: mutexInitCmpSwap
01:17
Fix typo in the Win32 implementation of sqlite3CompareAndSwap. check-in: 31a26a1d user: mistachkin tags: mutexInitCmpSwap
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/mutex.c.

    63     63         pFrom = sqlite3DefaultMutex();
    64     64       }else{
    65     65         pFrom = sqlite3NoopMutex();
    66     66       }
    67     67       mutexCopy(&sqlite3GlobalConfig.mutex, pFrom);
    68     68       sqlite3MemoryBarrier();
    69     69     }
           70  +  assert( sqlite3GlobalConfig.mutex.xMutexInit );
    70     71     rc = sqlite3GlobalConfig.mutex.xMutexInit();
    71     72   
    72     73   #ifdef SQLITE_DEBUG
    73     74     GLOBAL(int, mutexIsInit) = 1;
    74     75   #endif
    75     76   
    76     77     return rc;
................................................................................
    97     98   ** Retrieve a pointer to a static mutex or allocate a new dynamic one.
    98     99   */
    99    100   sqlite3_mutex *sqlite3_mutex_alloc(int id){
   100    101   #ifndef SQLITE_OMIT_AUTOINIT
   101    102     if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0;
   102    103     if( id>SQLITE_MUTEX_RECURSIVE && sqlite3MutexInit() ) return 0;
   103    104   #endif
          105  +  assert( sqlite3GlobalConfig.mutex.xMutexAlloc );
   104    106     return sqlite3GlobalConfig.mutex.xMutexAlloc(id);
   105    107   }
   106    108   
   107    109   sqlite3_mutex *sqlite3MutexAlloc(int id){
   108    110     if( !sqlite3GlobalConfig.bCoreMutex ){
   109    111       return 0;
   110    112     }
   111    113     assert( GLOBAL(int, mutexIsInit) );
          114  +  assert( sqlite3GlobalConfig.mutex.xMutexAlloc );
   112    115     return sqlite3GlobalConfig.mutex.xMutexAlloc(id);
   113    116   }
   114    117   
   115    118   /*
   116    119   ** Free a dynamic mutex.
   117    120   */
   118    121   void sqlite3_mutex_free(sqlite3_mutex *p){
   119    122     if( p ){
          123  +    assert( sqlite3GlobalConfig.mutex.xMutexFree );
   120    124       sqlite3GlobalConfig.mutex.xMutexFree(p);
   121    125     }
   122    126   }
   123    127   
   124    128   /*
   125    129   ** Obtain the mutex p. If some other thread already has the mutex, block
   126    130   ** until it can be obtained.
   127    131   */
   128    132   void sqlite3_mutex_enter(sqlite3_mutex *p){
   129    133     if( p ){
          134  +    assert( sqlite3GlobalConfig.mutex.xMutexEnter );
   130    135       sqlite3GlobalConfig.mutex.xMutexEnter(p);
   131    136     }
   132    137   }
   133    138   
   134    139   /*
   135    140   ** Obtain the mutex p. If successful, return SQLITE_OK. Otherwise, if another
   136    141   ** thread holds the mutex and it cannot be obtained, return SQLITE_BUSY.
   137    142   */
   138    143   int sqlite3_mutex_try(sqlite3_mutex *p){
   139    144     int rc = SQLITE_OK;
   140    145     if( p ){
          146  +    assert( sqlite3GlobalConfig.mutex.xMutexTry );
   141    147       return sqlite3GlobalConfig.mutex.xMutexTry(p);
   142    148     }
   143    149     return rc;
   144    150   }
   145    151   
   146    152   /*
   147    153   ** The sqlite3_mutex_leave() routine exits a mutex that was previously
   148    154   ** entered by the same thread.  The behavior is undefined if the mutex 
   149    155   ** is not currently entered. If a NULL pointer is passed as an argument
   150    156   ** this function is a no-op.
   151    157   */
   152    158   void sqlite3_mutex_leave(sqlite3_mutex *p){
   153    159     if( p ){
          160  +    assert( sqlite3GlobalConfig.mutex.xMutexLeave );
   154    161       sqlite3GlobalConfig.mutex.xMutexLeave(p);
   155    162     }
   156    163   }
   157    164   
   158    165   #ifndef NDEBUG
   159    166   /*
   160    167   ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are
   161    168   ** intended for use inside assert() statements.
   162    169   */
   163    170   int sqlite3_mutex_held(sqlite3_mutex *p){
          171  +  assert( p==0 || sqlite3GlobalConfig.mutex.xMutexHeld );
   164    172     return p==0 || sqlite3GlobalConfig.mutex.xMutexHeld(p);
   165    173   }
   166    174   int sqlite3_mutex_notheld(sqlite3_mutex *p){
          175  +  assert( p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld );
   167    176     return p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld(p);
   168    177   }
   169    178   #endif
   170    179   
   171    180   #endif /* !defined(SQLITE_MUTEX_OMIT) */