1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Add the SQLITE_OPEN_NOMUTEX flag. Used for opening connections that are not protected by an internal mutex. (CVS 5387)

FossilOrigin-Name: 7e58b78712420b3bd4320192a58d89eb71eecc9c
This commit is contained in:
danielk1977
2008-07-10 17:52:49 +00:00
parent 93a960a0a8
commit 9a6284c1bb
9 changed files with 85 additions and 28 deletions

View File

@ -1,5 +1,5 @@
C Remove\sunused\scode.\s\sTest\scoverage\senhancements.\s\sModify\sthe\salgorithm\sused\nto\sselect\scolumn\snames\sfor\sVIEWs\sof\sjoins\sso\sthat\sthe\sconstructed\scolumn\nnames\somits\sthe\sunderlying\stable\snames.\s(CVS\s5386)
D 2008-07-10T00:32:42
C Add\sthe\sSQLITE_OPEN_NOMUTEX\sflag.\sUsed\sfor\sopening\sconnections\sthat\sare\snot\sprotected\sby\san\sinternal\smutex.\s(CVS\s5387)
D 2008-07-10T17:52:49
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in a03f7cb4f7ad50bc53a788c6c544430e81f95de4
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -114,7 +114,7 @@ F src/insert.c e8efc17d037346e4a4a6949e72aab850befe3d5d
F src/journal.c cffd2cd214e58c0e99c3ff632b3bee6c7cbb260e
F src/legacy.c 3626c71fb70912abec9a4312beba753a9ce800df
F src/loadext.c ae0eed9fa96d74172d2a90ee63b5bc36d284295c
F src/main.c 62ed446133985350b94d16f986862bcdf108bbf2
F src/main.c 85517c4d61ed24f2d0230335aedd6270a69f59dd
F src/malloc.c 226a532e9e371d1bb3de2553bdd1f9b600ef099c
F src/md5.c 008216bbb5d34c6fbab5357aa68575ad8a31516a
F src/mem1.c 8340fa5f969e9f9b9bdeb54106457a2003456d2b
@ -142,13 +142,13 @@ F src/printf.c 8e5d410220cf8650f502caf71f0de979a3f9031e
F src/random.c 5c754319d38abdd6acd74601ee0105504adc508a
F src/select.c 0c887fe1a88ee40a11e71127f4e91a0d864508cd
F src/shell.c 484e7297e066f22830f9c15d7abbcdd2acb097b0
F src/sqlite.h.in 8a00ed8707a16ee724e9e500b07e9af3a6fcc9be
F src/sqlite.h.in 2fcdb1c1ee337d8371eb43a0c29294562b76ee23
F src/sqlite3ext.h 1e3887c9bd3ae66cb599e922824b04cd0d0f2c3e
F src/sqliteInt.h ca0dc923bcc51bef0064f34628bd6daeb0d68d38
F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8
F src/status.c b8d7b1f6b518e71986dfa65058de7a714efd61be
F src/table.c 22744786199c9195720c15a7a42cb97b2e2728d8
F src/tclsqlite.c 4dd9ee4cb44846ad9bcc4d0da8088c1e7d4b33d9
F src/tclsqlite.c ec46084184f033ba396a9ee7b5514b695083d0f3
F src/test1.c 30bdb22f911efd492c4f49565eae014330231ece
F src/test2.c c46d146019ab6e37474e66b3c789e5237d9ea7b7
F src/test3.c 3e9efdcac31466ccd1723fb074d65a4876d2f70f
@ -168,7 +168,7 @@ F src/test_hexio.c 2f1122aa3f012fa0142ee3c36ce5c902a70cd12f
F src/test_loadext.c df8ab3a6481ddebbdf0d28ebac5d9e0790f7860f
F src/test_malloc.c e9e1500f85c50964adc34892045410c08aaf67ff
F src/test_md5.c 28209a4e2068711b5443c33104fe41f21d160071
F src/test_mutex.c 64c88ef9fed47c896fe470af03bffcd0f6f058f2
F src/test_mutex.c 195d88dfc206d98ef6af3700c294c66a822e6378
F src/test_onefile.c 243157b10275251c5dc2d6619aee2ff9ae22379c
F src/test_osinst.c 867f1317bd135f942a63eab5a78da40fc70d1493
F src/test_schema.c 4b4bf7bb329326458c491b0e6facd4c8c4c5b479
@ -414,7 +414,7 @@ F test/misc5.test 0b68dcb630d44af2dbcdca94dd2b17c8d580f6fa
F test/misc6.test 953cc693924d88e6117aeba16f46f0bf5abede91
F test/misc7.test 68198e6a699f0e8e8e7641d597a9e77c87c961d6
F test/misuse.test 30b3a458e5a70c31e74c291937b6c82204c59f33
F test/mutex1.test 77719e9da234ba23f50e89e9fb19be8c116ad27a
F test/mutex1.test b0017a45203e92ddab9e27cc3d6bd5c8637925ac
F test/mutex2.test a006d753714ea7e00b90b6f9c061bdde5be16435
F test/nan.test 14c41572ff52dbc740b1c3303dd313a90dc6084c
F test/notnull.test 44d600f916b770def8b095a9962dbe3be5a70d82
@ -425,7 +425,7 @@ F test/pager2.test c025f91b75fe65e85febda64d9416428b8a5cab5
F test/pager3.test 2323bf27fd5bd887b580247e5bce500ceee994b4
F test/pageropt.test 6df72c441db0a037b7ec6990d16311c24fbea77b
F test/pagesize.test e0a8b3fe80f8b8e808d94a00734c7a18c76c407e
F test/permutations.test af83024a469d1cade2a6ca9ce33e61bcdd7c2672
F test/permutations.test 1a2047d4cded4f9c0a81fd16aa5ee47f9c3928de
F test/pragma.test e1984ed47f699a4a817008dab4111be31ee8b935
F test/pragma2.test 5364893491b9231dd170e3459bfc2e2342658b47
F test/printf.test 262a5acd3158f788e9bdf7f18d718f3af32ff6ef
@ -477,7 +477,7 @@ F test/substr.test 4be572ac017143e59b4058dc75c91a0d0dc6d4e0
F test/sync.test ded6b39d8d8ca3c0c5518516c6371b3316d3e3a3
F test/table.test 13b1c2e2fb4727b35ee1fb7641fc469214fd2455
F test/tableapi.test 892208d49e7be4817a4d3e4f641dbcbbee8cd03c
F test/tclsqlite.test 3dfb48f46de4353376fad835390b493ba066b4dc
F test/tclsqlite.test aa1781808502271feccfd24f9e2c0d2c1d7c496a
F test/tempdb.test b88ac8a19823cf771d742bf61eef93ef337c06b1
F test/temptable.test 19b851b9e3e64d91e9867619b2a3f5fffee6e125
F test/tester.tcl fbb53d7a92ab9156cf123a2dd47528a22c649860
@ -600,7 +600,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
P 2d8f7bebf0f13f3a95f1e2163e35d43229cabfea
R 3109bd577402694337300dc1871ab087
U drh
Z 3f0e22a5269e1c2844744b0925a32b3d
P 636cd723296a8b1709011fdd99b236ffddf3f1b0
R 1c142d83f8684ccc1bee7d1f443817bd
U danielk1977
Z 2f8219b821c41fd853a77ecdbb18c26b

View File

@ -1 +1 @@
636cd723296a8b1709011fdd99b236ffddf3f1b0
7e58b78712420b3bd4320192a58d89eb71eecc9c

View File

@ -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)) ){

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -9,7 +9,7 @@
#
#***********************************************************************
#
# $Id: mutex1.test,v 1.7 2008/07/08 02:12:37 drh Exp $
# $Id: mutex1.test,v 1.8 2008/07/10 17:52:49 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -130,6 +130,19 @@ ifcapable threadsafe {
}
sqlite3_enable_shared_cache $enable_shared_cache
# Open and use a connection in "nomutex" mode. Test that no recursive
# mutexes are obtained.
do_test mutex1.3.1 {
catch {db close}
clear_mutex_counters
sqlite3 db test.db -nomutex 1
execsql { SELECT * FROM abc }
} {1 2 3 1 2 3 1 2 3}
do_test mutex1.3.2 {
mutex_counters counters
set counters(recursive)
} {0}
do_test mutex1-X {
catch {db close}
sqlite3_shutdown

View File

@ -9,7 +9,7 @@
#
#***********************************************************************
#
# $Id: permutations.test,v 1.9 2008/06/27 14:05:25 danielk1977 Exp $
# $Id: permutations.test,v 1.10 2008/07/10 17:52:49 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -194,6 +194,25 @@ run_tests "singlethread" -description {
} SQLITE_OK
}
run_tests "nomutex" -description {
Tests run with the SQLITE_OPEN_SINGLETHREADED flag passed to sqlite3_open().
} -initialize {
rename sqlite3 sqlite3_nomutex
proc sqlite3 {args} {
if {[string range [lindex $args 0] 0 0] ne "-"} {
lappend args -nomutex 1
}
uplevel [concat sqlite3_nomutex $args]
}
} -include {
delete.test delete2.test insert.test rollback.test select1.test
select2.test trans.test update.test vacuum.test types.test
types2.test types3.test
} -shutdown {
rename sqlite3 {}
rename sqlite3_nomutex sqlite3
}
# Run some tests in SQLITE_CONFIG_MULTITHREAD mode.
#
run_tests "multithread" -description {

View File

@ -15,7 +15,7 @@
# interface is pretty well tested. This file contains some addition
# tests for fringe issues that the main test suite does not cover.
#
# $Id: tclsqlite.test,v 1.64 2008/04/28 13:02:58 drh Exp $
# $Id: tclsqlite.test,v 1.65 2008/07/10 17:52:49 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -25,7 +25,7 @@ source $testdir/tester.tcl
if {[sqlite3 -has-codec]} {
set r "sqlite_orig HANDLE FILENAME ?-key CODEC-KEY?"
} else {
set r "sqlite3 HANDLE FILENAME ?-vfs VFSNAME? ?-readonly BOOLEAN? ?-create BOOLEAN?"
set r "sqlite3 HANDLE FILENAME ?-vfs VFSNAME? ?-readonly BOOLEAN? ?-create BOOLEAN? ?-nomutex BOOLEAN?"
}
do_test tcl-1.1 {
set v [catch {sqlite3 bogus} msg]