/ Check-in [1a97bc81]
Login

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

Overview
Comment:Specifying an invalid mutex implementation (via SQLITE_CONFIG_MUTEX) should cause the default one to be used instead.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | mutexInitCmpSwap
Files: files | file ages | folders
SHA1: 1a97bc81ccfc88f2dd527dff16e9e395718675bc
User & Date: mistachkin 2015-09-12 04:19:51
Context
2015-09-12
04:22
Fix comments. check-in: de3fa51e user: mistachkin tags: mutexInitCmpSwap
04:19
Specifying an invalid mutex implementation (via SQLITE_CONFIG_MUTEX) should cause the default one to be used instead. check-in: 1a97bc81 user: mistachkin tags: mutexInitCmpSwap
03:40
Clarify the new mutex implementation reset logic in sqlite3_shutdown(). check-in: f9a03483 user: mistachkin tags: mutexInitCmpSwap
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/mutex.c.

    22     22   ** allocate a mutex while the system is uninitialized.
    23     23   */
    24     24   static SQLITE_WSD int mutexIsInit = 0;
    25     25   #endif /* SQLITE_DEBUG && !defined(SQLITE_MUTEX_OMIT) */
    26     26   
    27     27   
    28     28   #ifndef SQLITE_MUTEX_OMIT
           29  +/*
           30  +** This structure is for use by sqlite3MutexInit() only.  It represents an
           31  +** invalid mutex implementation (i.e. one where all the function pointers
           32  +** are null).
           33  +*/
           34  +static const sqlite3_mutex_methods mutexNullMethods = {
           35  +  0, /* xMutexInit */
           36  +  0, /* xMutexEnd */
           37  +  0, /* xMutexAlloc */
           38  +  0, /* xMutexFree */
           39  +  0, /* xMutexEnter */
           40  +  0, /* xMutexTry */
           41  +  0, /* xMutexLeave */
           42  +  0, /* xMutexHeld */
           43  +  0  /* xMutexNotheld */
           44  +};
           45  +
           46  +/*
           47  +** Returns non-zero if the currently configured mutex implemention is
           48  +** invalid (i.e. all of its function pointers are null).
           49  +*/
           50  +static int mutexIsInvalid(void){
           51  +  return memcmp(&sqlite3GlobalConfig.mutex, &mutexNullMethods,
           52  +                sizeof(sqlite3_mutex_methods))==0;
           53  +}
           54  +
    29     55   /*
    30     56   ** Copies a mutex implementation.  Both arguments must point to valid
    31     57   ** memory.
    32     58   */
    33     59   static void mutexCopy(
    34     60     sqlite3_mutex_methods *pTo,
    35     61     sqlite3_mutex_methods const *pFrom
................................................................................
    47     73   
    48     74   /*
    49     75   ** Initialize the mutex system.
    50     76   */
    51     77   int sqlite3MutexInit(void){ 
    52     78     int rc;
    53     79     if( sqlite3CompareAndSwap((void * volatile *)&sqlite3GlobalConfig.pMutex,
    54         -                            0, &sqlite3GlobalConfig.mutex)==0 ){
           80  +                   0, &sqlite3GlobalConfig.mutex)==0 || mutexIsInvalid() ){
    55     81       /* If the xMutexAlloc method has not been set, then the user did not
    56     82       ** install a mutex implementation via sqlite3_config() prior to 
    57     83       ** sqlite3_initialize() being called. This block copies pointers to
    58     84       ** the default implementation into the sqlite3GlobalConfig structure.
    59     85       */
    60     86       sqlite3_mutex_methods const *pFrom;
    61     87