/ Check-in [6225cd46]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Remove the obsolete static mutexes. Use only the lastest static mutex code. (CVS 4259)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 6225cd461cdd2132eeb480aa4deb8986b7f63c15
User & Date: drh 2007-08-21 13:51:23
Context
2007-08-21
14:27
Delay opening temporary pager files until they are first written. (CVS 4260) check-in: 3fb97a63 user: danielk1977 tags: trunk
13:51
Remove the obsolete static mutexes. Use only the lastest static mutex code. (CVS 4259) check-in: 6225cd46 user: drh tags: trunk
13:30
Add the tests that go with the previous commit. (CVS 4258) check-in: a87f32e1 user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/loadext.c.

   368    368   /*
   369    369   ** Register a statically linked extension that is automatically
   370    370   ** loaded by every new database connection.
   371    371   */
   372    372   int sqlite3_auto_extension(void *xInit){
   373    373     int i;
   374    374     int rc = SQLITE_OK;
   375         -  sqlite3_mutex *mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_GLOBAL);
          375  +  sqlite3_mutex *mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
   376    376     sqlite3_mutex_enter(mutex);
   377    377     for(i=0; i<nAutoExtension; i++){
   378    378       if( aAutoExtension[i]==xInit ) break;
   379    379     }
   380    380     if( i==nAutoExtension ){
   381    381       int nByte = (++nAutoExtension)*sizeof(aAutoExtension[0]);
   382    382       aAutoExtension = sqlite3_realloc(aAutoExtension, nByte);
................................................................................
   392    392     return rc;
   393    393   }
   394    394   
   395    395   /*
   396    396   ** Reset the automatic extension loading mechanism.
   397    397   */
   398    398   void sqlite3_reset_auto_extension(void){
   399         -  sqlite3_mutex *mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_GLOBAL);
          399  +  sqlite3_mutex *mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
   400    400     sqlite3_mutex_enter(mutex);
   401    401     sqlite3_free(aAutoExtension);
   402    402     aAutoExtension = 0;
   403    403     nAutoExtension = 0;
   404    404     sqlite3_mutex_leave(mutex);
   405    405   }
   406    406   
................................................................................
   415    415   
   416    416     if( nAutoExtension==0 ){
   417    417       /* Common case: early out without every having to acquire a mutex */
   418    418       return SQLITE_OK;
   419    419     }
   420    420     for(i=0; go; i++){
   421    421       char *zErrmsg = 0;
   422         -    sqlite3_mutex *mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_GLOBAL);
          422  +    sqlite3_mutex *mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
   423    423       sqlite3_mutex_enter(mutex);
   424    424       if( i>=nAutoExtension ){
   425    425         xInit = 0;
   426    426         go = 0;
   427    427       }else{
   428    428         xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*))
   429    429                 aAutoExtension[i];

Changes to src/os_unix.c.

   369    369   } sqlite3LockingStyle;
   370    370   #endif /* SQLITE_ENABLE_LOCKING_STYLE */
   371    371   
   372    372   /*
   373    373   ** Helper functions to obtain and relinquish the global mutex.
   374    374   */
   375    375   static void enterMutex(){
   376         -  sqlite3_mutex_enter(sqlite3_mutex_alloc(SQLITE_MUTEX_GLOBAL));
          376  +  sqlite3_mutex_enter(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER));
   377    377   }
   378    378   static void leaveMutex(){
   379         -  sqlite3_mutex_leave(sqlite3_mutex_alloc(SQLITE_MUTEX_GLOBAL));
          379  +  sqlite3_mutex_leave(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER));
   380    380   }
   381    381   
   382    382   #if SQLITE_THREADSAFE
   383    383   /*
   384    384   ** This variable records whether or not threads can override each others
   385    385   ** locks.
   386    386   **

Changes to src/random.c.

    11     11   *************************************************************************
    12     12   ** This file contains code to implement a pseudo-random number
    13     13   ** generator (PRNG) for SQLite.
    14     14   **
    15     15   ** Random numbers are used by some of the database backends in order
    16     16   ** to generate random integer keys for tables or random filenames.
    17     17   **
    18         -** $Id: random.c,v 1.19 2007/08/21 10:44:16 drh Exp $
           18  +** $Id: random.c,v 1.20 2007/08/21 13:51:23 drh Exp $
    19     19   */
    20     20   #include "sqliteInt.h"
    21     21   
    22     22   
    23     23   /*
    24     24   ** Get a single 8-bit random value from the RC4 PRNG.  The Mutex
    25     25   ** must be held while executing this routine.
................................................................................
    87     87   }
    88     88   
    89     89   /*
    90     90   ** Return N random bytes.
    91     91   */
    92     92   void sqlite3Randomness(int N, void *pBuf){
    93     93     unsigned char *zBuf = pBuf;
    94         -  sqlite3_mutex_enter(sqlite3_mutex_alloc(SQLITE_MUTEX_PRNG));
           94  +  static sqlite3_mutex *mutex = 0;
           95  +  if( mutex==0 ){
           96  +    mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_PRNG);
           97  +  }
           98  +  sqlite3_mutex_enter(mutex);
    95     99     while( N-- ){
    96    100       *(zBuf++) = randomByte();
    97    101     }
    98         -  sqlite3_mutex_leave(sqlite3_mutex_alloc(SQLITE_MUTEX_PRNG));
          102  +  sqlite3_mutex_leave(mutex);
    99    103   }

Changes to src/sqliteInt.h.

     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   ** Internal interface definitions for SQLite.
    13     13   **
    14         -** @(#) $Id: sqliteInt.h,v 1.593 2007/08/20 22:48:43 drh Exp $
           14  +** @(#) $Id: sqliteInt.h,v 1.594 2007/08/21 13:51:23 drh Exp $
    15     15   */
    16     16   #ifndef _SQLITEINT_H_
    17     17   #define _SQLITEINT_H_
    18     18   #include "sqliteLimit.h"
    19     19   
    20     20   
    21     21   #if defined(SQLITE_TCL) || defined(TCLSH)
................................................................................
   189    189   typedef sqlite_uint64 u64;         /* 8-byte unsigned integer */
   190    190   typedef UINT32_TYPE u32;           /* 4-byte unsigned integer */
   191    191   typedef UINT16_TYPE u16;           /* 2-byte unsigned integer */
   192    192   typedef INT16_TYPE i16;            /* 2-byte signed integer */
   193    193   typedef UINT8_TYPE u8;             /* 1-byte unsigned integer */
   194    194   typedef UINT8_TYPE i8;             /* 1-byte signed integer */
   195    195   
   196         -/*
   197         -** The mutex subsystem provides a handfull of static mutexes
   198         -** that are identified by small positive integers.  The following
   199         -** macros give symbolic names to those integers.
   200         -*/
   201         -#define SQLITE_MUTEX_MEM      1    /* Used by the memory allocator */
   202         -#define SQLITE_MUTEX_PRNG     2    /* Used by pseudorandom generator */
   203         -#define SQLITE_MUTEX_GLOBAL   3    /* Used by global variables */
   204         -#define SQLITE_MUTEX_STATIC_MAX 3
   205         -
   206    196   /*
   207    197   ** Macros to determine whether the machine is big or little endian,
   208    198   ** evaluated at runtime.
   209    199   */
   210    200   extern const int sqlite3one;
   211    201   #if defined(i386) || defined(__i386__) || defined(_M_IX86)
   212    202   # define SQLITE_BIGENDIAN    0