Index: third_party/sqlite/src/src/mutex.c |
diff --git a/third_party/sqlite/src/src/mutex.c b/third_party/sqlite/src/src/mutex.c |
index bad5a7c113c3f1065afaf1c3bf8d252cc073e389..6f1bc9767db8e1a3ce002bcc10b77c72c9e6f51c 100644 |
--- a/third_party/sqlite/src/src/mutex.c |
+++ b/third_party/sqlite/src/src/mutex.c |
@@ -22,7 +22,7 @@ |
** allocate a mutex while the system is uninitialized. |
*/ |
static SQLITE_WSD int mutexIsInit = 0; |
-#endif /* SQLITE_DEBUG */ |
+#endif /* SQLITE_DEBUG && !defined(SQLITE_MUTEX_OMIT) */ |
#ifndef SQLITE_MUTEX_OMIT |
@@ -45,11 +45,18 @@ int sqlite3MutexInit(void){ |
}else{ |
pFrom = sqlite3NoopMutex(); |
} |
- memcpy(pTo, pFrom, offsetof(sqlite3_mutex_methods, xMutexAlloc)); |
- memcpy(&pTo->xMutexFree, &pFrom->xMutexFree, |
- sizeof(*pTo) - offsetof(sqlite3_mutex_methods, xMutexFree)); |
+ pTo->xMutexInit = pFrom->xMutexInit; |
+ pTo->xMutexEnd = pFrom->xMutexEnd; |
+ pTo->xMutexFree = pFrom->xMutexFree; |
+ pTo->xMutexEnter = pFrom->xMutexEnter; |
+ pTo->xMutexTry = pFrom->xMutexTry; |
+ pTo->xMutexLeave = pFrom->xMutexLeave; |
+ pTo->xMutexHeld = pFrom->xMutexHeld; |
+ pTo->xMutexNotheld = pFrom->xMutexNotheld; |
+ sqlite3MemoryBarrier(); |
pTo->xMutexAlloc = pFrom->xMutexAlloc; |
} |
+ assert( sqlite3GlobalConfig.mutex.xMutexInit ); |
rc = sqlite3GlobalConfig.mutex.xMutexInit(); |
#ifdef SQLITE_DEBUG |
@@ -82,7 +89,9 @@ int sqlite3MutexEnd(void){ |
sqlite3_mutex *sqlite3_mutex_alloc(int id){ |
#ifndef SQLITE_OMIT_AUTOINIT |
if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0; |
+ if( id>SQLITE_MUTEX_RECURSIVE && sqlite3MutexInit() ) return 0; |
#endif |
+ assert( sqlite3GlobalConfig.mutex.xMutexAlloc ); |
return sqlite3GlobalConfig.mutex.xMutexAlloc(id); |
} |
@@ -91,6 +100,7 @@ sqlite3_mutex *sqlite3MutexAlloc(int id){ |
return 0; |
} |
assert( GLOBAL(int, mutexIsInit) ); |
+ assert( sqlite3GlobalConfig.mutex.xMutexAlloc ); |
return sqlite3GlobalConfig.mutex.xMutexAlloc(id); |
} |
@@ -99,6 +109,7 @@ sqlite3_mutex *sqlite3MutexAlloc(int id){ |
*/ |
void sqlite3_mutex_free(sqlite3_mutex *p){ |
if( p ){ |
+ assert( sqlite3GlobalConfig.mutex.xMutexFree ); |
sqlite3GlobalConfig.mutex.xMutexFree(p); |
} |
} |
@@ -109,6 +120,7 @@ void sqlite3_mutex_free(sqlite3_mutex *p){ |
*/ |
void sqlite3_mutex_enter(sqlite3_mutex *p){ |
if( p ){ |
+ assert( sqlite3GlobalConfig.mutex.xMutexEnter ); |
sqlite3GlobalConfig.mutex.xMutexEnter(p); |
} |
} |
@@ -120,6 +132,7 @@ void sqlite3_mutex_enter(sqlite3_mutex *p){ |
int sqlite3_mutex_try(sqlite3_mutex *p){ |
int rc = SQLITE_OK; |
if( p ){ |
+ assert( sqlite3GlobalConfig.mutex.xMutexTry ); |
return sqlite3GlobalConfig.mutex.xMutexTry(p); |
} |
return rc; |
@@ -133,6 +146,7 @@ int sqlite3_mutex_try(sqlite3_mutex *p){ |
*/ |
void sqlite3_mutex_leave(sqlite3_mutex *p){ |
if( p ){ |
+ assert( sqlite3GlobalConfig.mutex.xMutexLeave ); |
sqlite3GlobalConfig.mutex.xMutexLeave(p); |
} |
} |
@@ -143,9 +157,11 @@ void sqlite3_mutex_leave(sqlite3_mutex *p){ |
** intended for use inside assert() statements. |
*/ |
int sqlite3_mutex_held(sqlite3_mutex *p){ |
+ assert( p==0 || sqlite3GlobalConfig.mutex.xMutexHeld ); |
return p==0 || sqlite3GlobalConfig.mutex.xMutexHeld(p); |
} |
int sqlite3_mutex_notheld(sqlite3_mutex *p){ |
+ assert( p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld ); |
return p==0 || sqlite3GlobalConfig.mutex.xMutexNotheld(p); |
} |
#endif |