When the in single-threaded mode, the sqlite3_mutex_alloc() interface
still returns a non-NULL value. The mutex doesn't do anything, but it tests non-NULL. This way, extensions (or VFSes) that use sqlite3_mutex_alloc() can tell the difference between an OOM error and mutexes being disabled. FossilOrigin-Name: 451fd175758983c335aab449fdc4cb838156c4cb
This commit is contained in:
parent
7721b23e0a
commit
92d7652379
22
manifest
22
manifest
@ -1,8 +1,8 @@
|
||||
-----BEGIN PGP SIGNED MESSAGE-----
|
||||
Hash: SHA1
|
||||
|
||||
C When\ssqlite3PagerPagecount()\sis\scalled\swithout\sany\slocks,\salways\sreturn\nthe\sphysical\sfile\ssize,\snot\sthe\slogical\sfile\ssize.
|
||||
D 2010-05-04T18:50:40
|
||||
C When\sthe\sin\ssingle-threaded\smode,\sthe\ssqlite3_mutex_alloc()\sinterface\nstill\sreturns\sa\snon-NULL\svalue.\s\sThe\smutex\sdoesn't\sdo\sanything,\sbut\sit\ntests\snon-NULL.\s\sThis\sway,\sextensions\s(or\sVFSes)\sthat\suse\ssqlite3_mutex_alloc()\ncan\stell\sthe\sdifference\sbetween\san\sOOM\serror\sand\smutexes\sbeing\sdisabled.
|
||||
D 2010-05-05T00:05:24
|
||||
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
||||
F Makefile.in d83a0ffef3dcbfb08b410a6c6dd6c009ec9167fb
|
||||
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
||||
@ -142,9 +142,9 @@ F src/mem2.c 2ee7bdacda8299b5a91cff9f7ee3e46573195c38
|
||||
F src/mem3.c 9b237d911ba9904142a804be727cc6664873f8a3
|
||||
F src/mem5.c eb7a5cb98915dd7a086fa415ce3a5a0f20d0acff
|
||||
F src/memjournal.c f3be374af30588de297dcf678925b2a4758e4135
|
||||
F src/mutex.c c04412513619b3a763f3484bb412336fa3a3fbd9
|
||||
F src/mutex.c e2358d8f9a9021ab0bba4d511bb701e471e6e5f6
|
||||
F src/mutex.h 6fde601e55fa6c3fae768783c439797ab84c87c6
|
||||
F src/mutex_noop.c 5f58eaa31f2d742cb8957a747f7887ae98f16053
|
||||
F src/mutex_noop.c 7dcd084c1ecb6258b7da824fa0feb7d9ebd537d5
|
||||
F src/mutex_os2.c 20477db50cf3817c2f1cd3eb61e5c177e50231db
|
||||
F src/mutex_unix.c 04a25238abce7e3d06b358dcf706e26624270809
|
||||
F src/mutex_w32.c 4cc201c1bfd11d1562810554ff5500e735559d7e
|
||||
@ -171,7 +171,7 @@ F src/select.c c03d8a0565febcde8c6a12c5d77d065fddae889b
|
||||
F src/shell.c c40427c7245535a04a9cb4a417b6cc05c022e6a4
|
||||
F src/sqlite.h.in 7afbe9fb794092cb38bd3cfab72c39560ce0def5
|
||||
F src/sqlite3ext.h 69dfb8116af51b84a029cddb3b35062354270c89
|
||||
F src/sqliteInt.h e7f1368eb56d8a410e510bcffb9ca5795060c58c
|
||||
F src/sqliteInt.h 9819b45610abeca390176243a9a31758c1f0ac7a
|
||||
F src/sqliteLimit.h 196e2f83c3b444c4548fc1874f52f84fdbda40f3
|
||||
F src/status.c 4df6fe7dce2d256130b905847c6c60055882bdbe
|
||||
F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
|
||||
@ -812,14 +812,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
||||
P b15b67fa14ff77963f470678ff6188c63be8e079
|
||||
R 90a516a40aed68998882df9ec8564c82
|
||||
P 4016b422286587beda7323052d27821adb1fed73
|
||||
R 87640419095dfdb05fcc49f65da51e46
|
||||
U drh
|
||||
Z a30cf60f66607a4454bb94232875c47b
|
||||
Z 50e1e779e0d4bec5a929210a4c6c0526
|
||||
-----BEGIN PGP SIGNATURE-----
|
||||
Version: GnuPG v1.4.6 (GNU/Linux)
|
||||
|
||||
iD8DBQFL4GyCoxKgR168RlERAqJFAJ40lJ/yFBAWE6VloZv7iEujVoKLPQCeMvkL
|
||||
ZkjLFoOe5DHk4e/ITO6H6WY=
|
||||
=5Otc
|
||||
iD8DBQFL4LZKoxKgR168RlERAvf5AJ4yZOjWI5iQUOpLK97VFh220LzPgwCdHHWu
|
||||
b+V9an+7FFUytUxF3xEa9/c=
|
||||
=qvND
|
||||
-----END PGP SIGNATURE-----
|
||||
|
@ -1 +1 @@
|
||||
4016b422286587beda7323052d27821adb1fed73
|
||||
451fd175758983c335aab449fdc4cb838156c4cb
|
32
src/mutex.c
32
src/mutex.c
@ -31,23 +31,26 @@ static SQLITE_WSD int mutexIsInit = 0;
|
||||
*/
|
||||
int sqlite3MutexInit(void){
|
||||
int rc = SQLITE_OK;
|
||||
if( sqlite3GlobalConfig.bCoreMutex ){
|
||||
if( !sqlite3GlobalConfig.mutex.xMutexAlloc ){
|
||||
/* If the xMutexAlloc method has not been set, then the user did not
|
||||
** install a mutex implementation via sqlite3_config() prior to
|
||||
** sqlite3_initialize() being called. This block copies pointers to
|
||||
** the default implementation into the sqlite3GlobalConfig structure.
|
||||
*/
|
||||
sqlite3_mutex_methods *pFrom = sqlite3DefaultMutex();
|
||||
sqlite3_mutex_methods *pTo = &sqlite3GlobalConfig.mutex;
|
||||
if( !sqlite3GlobalConfig.mutex.xMutexAlloc ){
|
||||
/* If the xMutexAlloc method has not been set, then the user did not
|
||||
** install a mutex implementation via sqlite3_config() prior to
|
||||
** sqlite3_initialize() being called. This block copies pointers to
|
||||
** the default implementation into the sqlite3GlobalConfig structure.
|
||||
*/
|
||||
sqlite3_mutex_methods *pFrom;
|
||||
sqlite3_mutex_methods *pTo = &sqlite3GlobalConfig.mutex;
|
||||
|
||||
memcpy(pTo, pFrom, offsetof(sqlite3_mutex_methods, xMutexAlloc));
|
||||
memcpy(&pTo->xMutexFree, &pFrom->xMutexFree,
|
||||
sizeof(*pTo) - offsetof(sqlite3_mutex_methods, xMutexFree));
|
||||
pTo->xMutexAlloc = pFrom->xMutexAlloc;
|
||||
if( sqlite3GlobalConfig.bCoreMutex ){
|
||||
pFrom = sqlite3DefaultMutex();
|
||||
}else{
|
||||
pFrom = sqlite3NoopMutex();
|
||||
}
|
||||
rc = sqlite3GlobalConfig.mutex.xMutexInit();
|
||||
memcpy(pTo, pFrom, offsetof(sqlite3_mutex_methods, xMutexAlloc));
|
||||
memcpy(&pTo->xMutexFree, &pFrom->xMutexFree,
|
||||
sizeof(*pTo) - offsetof(sqlite3_mutex_methods, xMutexFree));
|
||||
pTo->xMutexAlloc = pFrom->xMutexAlloc;
|
||||
}
|
||||
rc = sqlite3GlobalConfig.mutex.xMutexInit();
|
||||
|
||||
#ifdef SQLITE_DEBUG
|
||||
GLOBAL(int, mutexIsInit) = 1;
|
||||
@ -77,7 +80,6 @@ int sqlite3MutexEnd(void){
|
||||
** Retrieve a pointer to a static mutex or allocate a new dynamic one.
|
||||
*/
|
||||
sqlite3_mutex *sqlite3_mutex_alloc(int id){
|
||||
if( !sqlite3GlobalConfig.bCoreMutex ) return 0;
|
||||
#ifndef SQLITE_OMIT_AUTOINIT
|
||||
if( sqlite3_initialize() ) return 0;
|
||||
#endif
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "sqliteInt.h"
|
||||
|
||||
|
||||
#if defined(SQLITE_MUTEX_NOOP) && !defined(SQLITE_DEBUG)
|
||||
#ifndef SQLITE_DEBUG
|
||||
/*
|
||||
** Stub routines for all mutex methods.
|
||||
**
|
||||
@ -44,7 +44,7 @@ static void noopMutexEnter(sqlite3_mutex *p){ return; }
|
||||
static int noopMutexTry(sqlite3_mutex *p){ return SQLITE_OK; }
|
||||
static void noopMutexLeave(sqlite3_mutex *p){ return; }
|
||||
|
||||
sqlite3_mutex_methods *sqlite3DefaultMutex(void){
|
||||
sqlite3_mutex_methods *sqlite3NoopMutex(void){
|
||||
static sqlite3_mutex_methods sMutex = {
|
||||
noopMutexInit,
|
||||
noopMutexEnd,
|
||||
@ -60,9 +60,9 @@ sqlite3_mutex_methods *sqlite3DefaultMutex(void){
|
||||
|
||||
return &sMutex;
|
||||
}
|
||||
#endif /* defined(SQLITE_MUTEX_NOOP) && !defined(SQLITE_DEBUG) */
|
||||
#endif /* !SQLITE_DEBUG */
|
||||
|
||||
#if defined(SQLITE_MUTEX_NOOP) && defined(SQLITE_DEBUG)
|
||||
#ifdef SQLITE_DEBUG
|
||||
/*
|
||||
** In this implementation, error checking is provided for testing
|
||||
** and debugging purposes. The mutexes still do not provide any
|
||||
@ -165,7 +165,7 @@ static void debugMutexLeave(sqlite3_mutex *p){
|
||||
assert( p->id==SQLITE_MUTEX_RECURSIVE || debugMutexNotheld(p) );
|
||||
}
|
||||
|
||||
sqlite3_mutex_methods *sqlite3DefaultMutex(void){
|
||||
sqlite3_mutex_methods *sqlite3NoopMutex(void){
|
||||
static sqlite3_mutex_methods sMutex = {
|
||||
debugMutexInit,
|
||||
debugMutexEnd,
|
||||
@ -181,4 +181,14 @@ sqlite3_mutex_methods *sqlite3DefaultMutex(void){
|
||||
|
||||
return &sMutex;
|
||||
}
|
||||
#endif /* defined(SQLITE_MUTEX_NOOP) && defined(SQLITE_DEBUG) */
|
||||
#endif /* SQLITE_DEBUG */
|
||||
|
||||
/*
|
||||
** If compiled with SQLITE_MUTEX_NOOP, then the no-op mutex implementation
|
||||
** is used regardless of the run-time threadsafety setting.
|
||||
*/
|
||||
#ifdef SQLITE_MUTEX_NOOP
|
||||
sqlite3_mutex_methods *sqlite3DefaultMutex(void){
|
||||
return sqliteNoopMutex();
|
||||
}
|
||||
#endif /* SQLITE_MUTEX_NOOP */
|
||||
|
@ -2537,6 +2537,7 @@ const sqlite3_mem_methods *sqlite3MemGetMemsys5(void);
|
||||
|
||||
#ifndef SQLITE_MUTEX_OMIT
|
||||
sqlite3_mutex_methods *sqlite3DefaultMutex(void);
|
||||
sqlite3_mutex_methods *sqlite3NoopMutex(void);
|
||||
sqlite3_mutex *sqlite3MutexAlloc(int);
|
||||
int sqlite3MutexInit(void);
|
||||
int sqlite3MutexEnd(void);
|
||||
|
Loading…
x
Reference in New Issue
Block a user