-C Add\sstatic\smutexes\sfor\suse\sby\sthe\sbuilt-in\s/\sthird-party\sVFSs\sand\suse\sthe\sbuilt-in\sVFS\smutex\swhere\sappropriate.
-D 2015-07-03T21:38:09.670
+C Enhance\smutex\stesting\sto\sinclude\sAPP\sand\sVFS\sstatic\smutexes.
+D 2015-07-03T23:11:36.336
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 78db7e3b643002849258892ab2a9df10c24ee63d
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
F src/test_malloc.c 208f09a4e21defa496bc1094fcfadea19385a112
F src/test_multiplex.c 9fefd23f6cc3fa9bf0748a5e453167e7b9f193ce
F src/test_multiplex.h c08e4e8f8651f0c5e0509b138ff4d5b43ed1f5d3
-F src/test_mutex.c 293042d623ebba969160f471a82aa1551626454f
+F src/test_mutex.c 486bea424c66005d587e8272b2a742a25d251c73
F src/test_onefile.c 38f7cbe79d5bafe95bde683cc3a53b8ca16daf10
F src/test_osinst.c 5423dc1d355f594371f27dd292ca54bd320b8196
F src/test_pcache.c a5cd24730cb43c5b18629043314548c9169abb00
F test/multiplex2.test 580ca5817c7edbe4cc68fa150609c9473393003a
F test/multiplex3.test d228f59eac91839a977eac19f21d053f03e4d101
F test/multiplex4.test e8ae4c4bd70606a5727743241f13b5701990abe4
-F test/mutex1.test 78b2b9bb320e51d156c4efdb71b99b051e7a4b41
+F test/mutex1.test e0a44072d98189003deae4b091106f085d94bea8
F test/mutex2.test bfeaeac2e73095b2ac32285d2756e3a65e681660
F test/nan.test e9648b9d007c7045242af35e11a984d4b169443a
F test/nolock.test 0540dd96f39b8876e3ffdd8814fad0ea425efeee
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 0778825d0ec9315c70659fae8d0640b209049dd8
-R c3e93636a97f33c44303b10895e73ee1
+P b202e2a1d73d104d795d2252b1c6f61d65bfb295
+R 1dd264571c6a612a20dc2b3433c44096
U mistachkin
-Z 0231ff1cbe7c5e5e0d327907d22772e6
+Z 47fb3c7897d245bf0611496fd190514f
#include <assert.h>
#include <string.h>
+#define MAX_MUTEXES (SQLITE_MUTEX_STATIC_VFS3+1)
+
/* defined in main.c */
extern const char *sqlite3ErrName(int);
+static const char *aName[MAX_MUTEXES+1] = {
+ "fast", "recursive", "static_master", "static_mem",
+ "static_open", "static_prng", "static_lru", "static_pmem",
+ "static_app1", "static_app2", "static_app3", "static_vfs1",
+ "static_vfs2", "static_vfs3", 0
+};
+
/* A countable mutex */
struct sqlite3_mutex {
sqlite3_mutex *pReal;
/* State variables */
static struct test_mutex_globals {
- int isInstalled; /* True if installed */
- int disableInit; /* True to cause sqlite3_initalize() to fail */
- int disableTry; /* True to force sqlite3_mutex_try() to fail */
- int isInit; /* True if initialized */
- sqlite3_mutex_methods m; /* Interface to "real" mutex system */
- int aCounter[8]; /* Number of grabs of each type of mutex */
- sqlite3_mutex aStatic[6]; /* The six static mutexes */
+ int isInstalled; /* True if installed */
+ int disableInit; /* True to cause sqlite3_initalize() to fail */
+ int disableTry; /* True to force sqlite3_mutex_try() to fail */
+ int isInit; /* True if initialized */
+ sqlite3_mutex_methods m; /* Interface to "real" mutex system */
+ int aCounter[MAX_MUTEXES]; /* Number of grabs of each type of mutex */
+ sqlite3_mutex aStatic[MAX_MUTEXES]; /* The static mutexes */
} g = {0};
/* Return true if the countable mutex is currently held */
sqlite3_mutex *pRet = 0;
assert( g.isInit );
- assert(eType<8 && eType>=0);
+ assert( eType>=SQLITE_MUTEX_FAST );
+ assert( eType<=SQLITE_MUTEX_STATIC_VFS3 );
pReal = g.m.xMutexAlloc(eType);
if( !pReal ) return 0;
if( eType==SQLITE_MUTEX_FAST || eType==SQLITE_MUTEX_RECURSIVE ){
pRet = (sqlite3_mutex *)malloc(sizeof(sqlite3_mutex));
}else{
- pRet = &g.aStatic[eType-2];
+ int eStaticType = eType - (SQLITE_MUTEX_RECURSIVE + 1);
+ assert( eStaticType>=0 );
+ assert( eStaticType<MAX_MUTEXES );
+ pRet = &g.aStatic[eStaticType];
}
pRet->eType = eType;
*/
static void counterMutexEnter(sqlite3_mutex *p){
assert( g.isInit );
+ assert( p->eType>=0 );
+ assert( p->eType<MAX_MUTEXES );
g.aCounter[p->eType]++;
g.m.xMutexEnter(p->pReal);
}
*/
static int counterMutexTry(sqlite3_mutex *p){
assert( g.isInit );
+ assert( p->eType>=0 );
+ assert( p->eType<MAX_MUTEXES );
g.aCounter[p->eType]++;
if( g.disableTry ) return SQLITE_BUSY;
return g.m.xMutexTry(p->pReal);
){
Tcl_Obj *pRet;
int ii;
- char *aName[8] = {
- "fast", "recursive", "static_master", "static_mem",
- "static_open", "static_prng", "static_lru", "static_pmem"
- };
if( objc!=1 ){
Tcl_WrongNumArgs(interp, 1, objv, "");
pRet = Tcl_NewObj();
Tcl_IncrRefCount(pRet);
- for(ii=0; ii<8; ii++){
+ for(ii=0; ii<MAX_MUTEXES; ii++){
Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj(aName[ii], -1));
Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(g.aCounter[ii]));
}
return TCL_ERROR;
}
- for(ii=0; ii<8; ii++){
+ for(ii=0; ii<MAX_MUTEXES; ii++){
g.aCounter[ii] = 0;
}
return TCL_OK;
return db;
}
+static sqlite3_mutex *getStaticMutexPointer(
+ Tcl_Interp *pInterp,
+ Tcl_Obj *pObj
+){
+ int iMutex;
+ if( Tcl_GetIndexFromObj(pInterp, pObj, aName, "mutex name", 0, &iMutex) ){
+ return 0;
+ }
+ assert( iMutex!=SQLITE_MUTEX_FAST && iMutex!=SQLITE_MUTEX_RECURSIVE );
+ return counterMutexAlloc(iMutex);
+}
+
+static int test_enter_static_mutex(
+ void * clientData,
+ Tcl_Interp *interp,
+ int objc,
+ Tcl_Obj *CONST objv[]
+){
+ sqlite3_mutex *pMutex;
+ if( objc!=2 ){
+ Tcl_WrongNumArgs(interp, 1, objv, "NAME");
+ return TCL_ERROR;
+ }
+ pMutex = getStaticMutexPointer(interp, objv[1]);
+ if( !pMutex ){
+ return TCL_ERROR;
+ }
+ sqlite3_mutex_enter(pMutex);
+ return TCL_OK;
+}
+
+static int test_leave_static_mutex(
+ void * clientData,
+ Tcl_Interp *interp,
+ int objc,
+ Tcl_Obj *CONST objv[]
+){
+ sqlite3_mutex *pMutex;
+ if( objc!=2 ){
+ Tcl_WrongNumArgs(interp, 1, objv, "NAME");
+ return TCL_ERROR;
+ }
+ pMutex = getStaticMutexPointer(interp, objv[1]);
+ if( !pMutex ){
+ return TCL_ERROR;
+ }
+ sqlite3_mutex_leave(pMutex);
+ return TCL_OK;
+}
+
static int test_enter_db_mutex(
void * clientData,
Tcl_Interp *interp,
{ "sqlite3_initialize", (Tcl_ObjCmdProc*)test_initialize },
{ "sqlite3_config", (Tcl_ObjCmdProc*)test_config },
+ { "enter_static_mutex", (Tcl_ObjCmdProc*)test_enter_static_mutex },
+ { "leave_static_mutex", (Tcl_ObjCmdProc*)test_leave_static_mutex },
+
{ "enter_db_mutex", (Tcl_ObjCmdProc*)test_enter_db_mutex },
{ "leave_db_mutex", (Tcl_ObjCmdProc*)test_leave_db_mutex },
#-------------------------------------------------------------------------
# Tests mutex1-1.* test that sqlite3_config() returns SQLITE_MISUSE if
-# is called at the wrong time. And that the first time sqlite3_initialize
+# is called at the wrong time. And that the first time sqlite3_initialize
# is called it obtains the 'static_master' mutex 3 times and a recursive
-# mutex (sqlite3Config.pInitMutex) twice. Subsequent calls are no-ops
+# mutex (sqlite3Config.pInitMutex) twice. Subsequent calls are no-ops
# that do not require any mutexes.
#
do_test mutex1-1.0 {
foreach {mode mutexes} {
singlethread {}
multithread {
- fast static_lru static_master static_mem static_open static_prng
- static_pmem
+ fast static_app1 static_app2 static_app3
+ static_lru static_master static_mem static_open
+ static_prng static_pmem static_vfs1 static_vfs2
+ static_vfs3
}
serialized {
- fast recursive static_lru static_master static_mem static_open
- static_prng static_pmem
+ fast recursive static_app1 static_app2
+ static_app3 static_lru static_master static_mem
+ static_open static_prng static_pmem static_vfs1
+ static_vfs2 static_vfs3
}
} {
ifcapable !memorymanage {
regsub { static_lru} $mutexes {} mutexes
}
- do_test mutex1.2.$mode.3 {
+ if {$mode ne "singlethread"} {
+ do_test mutex1.2.$mode.3 {
+ #
+ # NOTE: Make sure all the app and vfs mutexes get used.
+ #
+ enter_static_mutex static_app1
+ leave_static_mutex static_app1
+ enter_static_mutex static_app2
+ leave_static_mutex static_app2
+ enter_static_mutex static_app3
+ leave_static_mutex static_app3
+ enter_static_mutex static_vfs1
+ leave_static_mutex static_vfs1
+ enter_static_mutex static_vfs2
+ leave_static_mutex static_vfs2
+ enter_static_mutex static_vfs3
+ leave_static_mutex static_vfs3
+ } {}
+ }
+ do_test mutex1.2.$mode.4 {
mutex_counters counters
-
+
set res [list]
foreach {key value} [array get counters] {
if {$key ne "total" && $value > 0} {