Index: third_party/sqlite/src/src/test_mutex.c |
diff --git a/third_party/sqlite/src/src/test_mutex.c b/third_party/sqlite/src/src/test_mutex.c |
index c9b4a29ab75c77ea5f36b5193256d70fe6580e95..995b89a4c64f264b5fc062133e3fd9d6467921e1 100644 |
--- a/third_party/sqlite/src/src/test_mutex.c |
+++ b/third_party/sqlite/src/src/test_mutex.c |
@@ -19,9 +19,19 @@ |
#include <assert.h> |
#include <string.h> |
+#define MAX_MUTEXES (SQLITE_MUTEX_STATIC_VFS3+1) |
+#define STATIC_MUTEXES (MAX_MUTEXES-(SQLITE_MUTEX_RECURSIVE+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; |
@@ -30,13 +40,13 @@ struct sqlite3_mutex { |
/* 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[STATIC_MUTEXES]; /* The static mutexes */ |
} g = {0}; |
/* Return true if the countable mutex is currently held */ |
@@ -78,7 +88,8 @@ static sqlite3_mutex *counterMutexAlloc(int eType){ |
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; |
@@ -86,7 +97,10 @@ static sqlite3_mutex *counterMutexAlloc(int eType){ |
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 - (MAX_MUTEXES - STATIC_MUTEXES); |
+ assert( eStaticType>=0 ); |
+ assert( eStaticType<STATIC_MUTEXES ); |
+ pRet = &g.aStatic[eStaticType]; |
} |
pRet->eType = eType; |
@@ -110,6 +124,8 @@ static void counterMutexFree(sqlite3_mutex *p){ |
*/ |
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); |
} |
@@ -119,6 +135,8 @@ static void counterMutexEnter(sqlite3_mutex *p){ |
*/ |
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); |
@@ -245,10 +263,6 @@ static int test_read_mutex_counters( |
){ |
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, ""); |
@@ -257,7 +271,7 @@ static int test_read_mutex_counters( |
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])); |
} |
@@ -283,7 +297,7 @@ static int test_clear_mutex_counters( |
return TCL_ERROR; |
} |
- for(ii=0; ii<8; ii++){ |
+ for(ii=0; ii<MAX_MUTEXES; ii++){ |
g.aCounter[ii] = 0; |
} |
return TCL_OK; |
@@ -371,6 +385,56 @@ static sqlite3 *getDbPointer(Tcl_Interp *pInterp, Tcl_Obj *pObj){ |
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, |
@@ -418,6 +482,9 @@ int Sqlitetest_mutex_Init(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 }, |