diff options
author | danielk1977 <danielk1977@noemail.net> | 2008-06-17 18:57:49 +0000 |
---|---|---|
committer | danielk1977 <danielk1977@noemail.net> | 2008-06-17 18:57:49 +0000 |
commit | b2e36222afe9183acdb96e09cd0ce4538d72992b (patch) | |
tree | b40ee23aaacae6001e757027680738ed3cec8286 /src | |
parent | 6d2ab0e4318e293000c42fb667bf0a16a198ce0e (diff) | |
download | sqlite-b2e36222afe9183acdb96e09cd0ce4538d72992b.tar.gz sqlite-b2e36222afe9183acdb96e09cd0ce4538d72992b.zip |
Add the SQLITE_CONFIG_MUTEX symbol for use with sqlite3_config(). (CVS 5228)
FossilOrigin-Name: af1835bb5f5e3fb78d782c7c287e20db169e883f
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 9 | ||||
-rw-r--r-- | src/mutex.c | 15 | ||||
-rw-r--r-- | src/sqlite.h.in | 3 |
3 files changed, 21 insertions, 6 deletions
diff --git a/src/main.c b/src/main.c index 803c0ec4b..af2576e45 100644 --- a/src/main.c +++ b/src/main.c @@ -14,7 +14,7 @@ ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** -** $Id: main.c,v 1.445 2008/06/16 20:51:16 drh Exp $ +** $Id: main.c,v 1.446 2008/06/17 18:57:49 danielk1977 Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -76,9 +76,7 @@ int sqlite3_initialize(void){ if( sqlite3IsInit ) return SQLITE_OK; rc = sqlite3_mutex_init(); if( rc==SQLITE_OK ){ -#ifndef SQLITE_MUTEX_NOOP sqlite3_mutex *pMutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER); -#endif sqlite3_mutex_enter(pMutex); if( sqlite3IsInit==0 ){ sqlite3IsInit = 1; @@ -153,6 +151,11 @@ int sqlite3_config(int op, ...){ sqlite3Config.m = *va_arg(ap, sqlite3_mem_methods*); break; } + case SQLITE_CONFIG_MUTEX: { + /* Specify an alternative mutex implementation */ + sqlite3Config.mutex = *va_arg(ap, sqlite3_mutex_methods*); + break; + } case SQLITE_CONFIG_MEMSTATUS: { /* Enable or disable the malloc status collection */ sqlite3Config.bMemstat = va_arg(ap, int); diff --git a/src/mutex.c b/src/mutex.c index 3eded653b..46bb82d71 100644 --- a/src/mutex.c +++ b/src/mutex.c @@ -19,7 +19,7 @@ ** implementation is suitable for testing. ** debugging purposes ** -** $Id: mutex.c,v 1.21 2008/06/17 17:21:18 danielk1977 Exp $ +** $Id: mutex.c,v 1.22 2008/06/17 18:57:49 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -30,12 +30,24 @@ int sqlite3_mutex_init(void){ int rc; if( !sqlite3Config.mutex.xMutexAlloc ){ + /* If the xMutexAlloc method has not been set, then the user did not + ** install a mutex implementation via sqlite3_config() prior to + ** sqlite3_initialize() being called. This block copies pointers to + ** the default implementation into the sqlite3Config structure. + ** + ** The danger is that although sqlite3_config() is not a threadsafe + ** API, sqlite3_initialize() is, and so multiple threads may be + ** attempting to run this function simultaneously. To guard write + ** access to the sqlite3Config structure, the 'MASTER' static mutex + ** is obtained before modifying it. + */ sqlite3_mutex_methods *p = sqlite3DefaultMutex(); sqlite3_mutex *pMaster; rc = p->xMutexInit(); if( rc==SQLITE_OK ){ pMaster = p->xMutexAlloc(SQLITE_MUTEX_STATIC_MASTER); + assert(pMaster); p->xMutexEnter(pMaster); assert( sqlite3Config.mutex.xMutexAlloc==0 || sqlite3Config.mutex.xMutexAlloc==p->xMutexAlloc @@ -45,7 +57,6 @@ int sqlite3_mutex_init(void){ } p->xMutexLeave(pMaster); } - }else{ rc = sqlite3Config.mutex.xMutexInit(); } diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 592b1e174..d9b8921aa 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -30,7 +30,7 @@ ** the version number) and changes its name to "sqlite3.h" as ** part of the build process. ** -** @(#) $Id: sqlite.h.in,v 1.330 2008/06/17 17:21:18 danielk1977 Exp $ +** @(#) $Id: sqlite.h.in,v 1.331 2008/06/17 18:57:49 danielk1977 Exp $ */ #ifndef _SQLITE3_H_ #define _SQLITE3_H_ @@ -1050,6 +1050,7 @@ struct sqlite3_mem_methods { #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ #define SQLITE_CONFIG_MEMSTATUS 5 /* boolean */ +#define SQLITE_CONFIG_MUTEX 6 /* sqlite3_mutex_methods* */ /* These options are to be added later. Currently unused and undocumented. */ #define SQLITE_CONFIG_HEAP 6 /* void*, int64, min, max, tmp */ |