diff options
author | danielk1977 <danielk1977@noemail.net> | 2008-07-10 17:52:49 +0000 |
---|---|---|
committer | danielk1977 <danielk1977@noemail.net> | 2008-07-10 17:52:49 +0000 |
commit | 9a6284c1bba40b606a01356ebe962691e1ce256a (patch) | |
tree | 23dc252d6c87353e8b125b02d4ce80d9144b0478 /src | |
parent | 93a960a0a8a537784e4f40db2ad06686618a234e (diff) | |
download | sqlite-9a6284c1bba40b606a01356ebe962691e1ce256a.tar.gz sqlite-9a6284c1bba40b606a01356ebe962691e1ce256a.zip |
Add the SQLITE_OPEN_NOMUTEX flag. Used for opening connections that are not protected by an internal mutex. (CVS 5387)
FossilOrigin-Name: 7e58b78712420b3bd4320192a58d89eb71eecc9c
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 14 | ||||
-rw-r--r-- | src/sqlite.h.in | 15 | ||||
-rw-r--r-- | src/tclsqlite.c | 13 | ||||
-rw-r--r-- | src/test_mutex.c | 3 |
4 files changed, 35 insertions, 10 deletions
diff --git a/src/main.c b/src/main.c index c3a89488c..e8c47ac56 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.473 2008/07/09 13:28:54 drh Exp $ +** $Id: main.c,v 1.474 2008/07/10 17:52:49 danielk1977 Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -1247,12 +1247,17 @@ static int openDatabase( sqlite3 *db; int rc; CollSeq *pColl; + int isThreadsafe = 1; #ifndef SQLITE_OMIT_AUTOINIT rc = sqlite3_initialize(); if( rc ) return rc; #endif + if( flags&SQLITE_OPEN_NOMUTEX ){ + isThreadsafe = 0; + } + /* Remove harmful bits from the flags parameter */ flags &= ~( SQLITE_OPEN_DELETEONCLOSE | SQLITE_OPEN_MAIN_DB | @@ -1261,13 +1266,14 @@ static int openDatabase( SQLITE_OPEN_MAIN_JOURNAL | SQLITE_OPEN_TEMP_JOURNAL | SQLITE_OPEN_SUBJOURNAL | - SQLITE_OPEN_MASTER_JOURNAL + SQLITE_OPEN_MASTER_JOURNAL | + SQLITE_OPEN_NOMUTEX ); /* Allocate the sqlite data structure */ db = sqlite3MallocZero( sizeof(sqlite3) ); if( db==0 ) goto opendb_out; - if( sqlite3Config.bFullMutex ){ + if( sqlite3Config.bFullMutex && isThreadsafe ){ db->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE); if( db->mutex==0 ){ sqlite3_free(db); @@ -1424,7 +1430,7 @@ static int openDatabase( opendb_out: if( db ){ - assert( db->mutex!=0 || sqlite3Config.bFullMutex==0 ); + assert( db->mutex!=0 || isThreadsafe==0 || sqlite3Config.bFullMutex==0 ); sqlite3_mutex_leave(db->mutex); } if( SQLITE_NOMEM==(rc = sqlite3_errcode(db)) ){ diff --git a/src/sqlite.h.in b/src/sqlite.h.in index bb4ba97ad..ab433fdf0 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.365 2008/07/09 13:28:54 drh Exp $ +** @(#) $Id: sqlite.h.in,v 1.366 2008/07/10 17:52:49 danielk1977 Exp $ */ #ifndef _SQLITE3_H_ #define _SQLITE3_H_ @@ -512,6 +512,7 @@ int sqlite3_exec( #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 #define SQLITE_OPEN_SUBJOURNAL 0x00002000 #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 +#define SQLITE_OPEN_NOMUTEX 0x00008000 /* ** CAPI3REF: Device Characteristics {F10240} @@ -2296,7 +2297,9 @@ void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); ** ** The sqlite3_open_v2() interface works like sqlite3_open() ** except that it accepts two additional parameters for additional control -** over the new database connection. The flags parameter can be one of: +** over the new database connection. The flags parameter can take one of +** the following three values, optionally combined with the +** SQLITE_OPEN_NOMUTEX flag: ** ** <dl> ** <dt>[SQLITE_OPEN_READONLY]</dt> @@ -2315,7 +2318,13 @@ void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); ** </dl> ** ** If the 3rd parameter to sqlite3_open_v2() is not one of the -** combinations shown above then the behavior is undefined. +** combinations shown above or one of the combinations shown above combined +** with the SQLITE_OPEN_NOMUTEX flag, then the behavior is undefined. +** +** If the SQLITE_OPEN_NOMUTEX flag is set, then the opened database handle +** is not threadsafe. If two threads attempt to use the database handle or +** any of it's statement handles simultaneously, the results will be +** unpredictable. ** ** If the filename is ":memory:", then a private, temporary in-memory database ** is created for the connection. This in-memory database will vanish when diff --git a/src/tclsqlite.c b/src/tclsqlite.c index ab00763db..35a69b8c1 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -12,7 +12,7 @@ ** A TCL Interface to SQLite. Append this file to sqlite3.c and ** compile the whole thing to build a TCL-enabled version of SQLite. ** -** $Id: tclsqlite.c,v 1.218 2008/06/18 09:45:56 danielk1977 Exp $ +** $Id: tclsqlite.c,v 1.219 2008/07/10 17:52:49 danielk1977 Exp $ */ #include "tcl.h" #include <errno.h> @@ -2299,7 +2299,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ /* ** sqlite3 DBNAME FILENAME ?-vfs VFSNAME? ?-key KEY? ?-readonly BOOLEAN? -** ?-create BOOLEAN? +** ?-create BOOLEAN? ?-nomutex BOOLEAN? ** ** This is the main Tcl command. When the "sqlite" Tcl command is ** invoked, this routine runs to process that command. @@ -2363,6 +2363,14 @@ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ }else{ flags &= ~SQLITE_OPEN_CREATE; } + }else if( strcmp(zArg, "-nomutex")==0 ){ + int b; + if( Tcl_GetBooleanFromObj(interp, objv[i+1], &b) ) return TCL_ERROR; + if( b ){ + flags |= SQLITE_OPEN_NOMUTEX; + }else{ + flags &= ~SQLITE_OPEN_NOMUTEX; + } }else{ Tcl_AppendResult(interp, "unknown option: ", zArg, (char*)0); return TCL_ERROR; @@ -2371,6 +2379,7 @@ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ if( objc<3 || (objc&1)!=1 ){ Tcl_WrongNumArgs(interp, 1, objv, "HANDLE FILENAME ?-vfs VFSNAME? ?-readonly BOOLEAN? ?-create BOOLEAN?" + " ?-nomutex BOOLEAN?" #ifdef SQLITE_HAS_CODEC " ?-key CODECKEY?" #endif diff --git a/src/test_mutex.c b/src/test_mutex.c index 817de93ac..2de4a1b9c 100644 --- a/src/test_mutex.c +++ b/src/test_mutex.c @@ -10,7 +10,7 @@ ** ************************************************************************* ** -** $Id: test_mutex.c,v 1.6 2008/07/08 02:12:37 drh Exp $ +** $Id: test_mutex.c,v 1.7 2008/07/10 17:52:49 danielk1977 Exp $ */ #include "tcl.h" @@ -18,6 +18,7 @@ #include <stdlib.h> #include <assert.h> #include <string.h> +#include "mutex.h" /* defined in test1.c */ const char *sqlite3TestErrorName(int); |