]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Implement the 'CONFIG_SINGLETHREAD' and 'CONFIG_MULTITHREAD' configuration modes...
authordanielk1977 <danielk1977@noemail.net>
Wed, 18 Jun 2008 17:09:10 +0000 (17:09 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Wed, 18 Jun 2008 17:09:10 +0000 (17:09 +0000)
FossilOrigin-Name: 5059644c4bc5f6679afd939e0bc26080f42a9918

24 files changed:
manifest
manifest.uuid
src/btree.c
src/date.c
src/loadext.c
src/main.c
src/malloc.c
src/mem2.c
src/mem3.c
src/mem4.c
src/mem5.c
src/mutex.c
src/os.c
src/os_unix.c
src/pager.c
src/random.c
src/sqliteInt.h
src/test3.c
src/test_mutex.c
src/vdbeapi.c
test/mutex1.test
test/mutex2.test [new file with mode: 0644]
test/quick.test
test/veryquick.test

index bf2af3b858c4e67d82511652e08b44197322f1cd..1137269b498de77f8c4ce103e6f20de5049a0378 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Make\ssure\saggregate\sfunctions\scan\stake\sany\snumber\sof\sarguments\sup\sto\sthe\nlimit\simposed\sby\sSQLITE_LIMIT_FUNCTION_ARGS.\s\sTicket\s#3179.\s\sModify\nthe\sgroup_concat()\sfunction\sto\stake\san\sunlimited\snumber\sof\sarguments\sin\norder\sto\sfacilitate\stesting\sthis\sbehavior.\s(CVS\s5233)
-D 2008-06-18T15:34:10
+C Implement\sthe\s'CONFIG_SINGLETHREAD'\sand\s'CONFIG_MULTITHREAD'\sconfiguration\smodes.\s(CVS\s5234)
+D 2008-06-18T17:09:10
 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
 F Makefile.in dc5608df93faf4406cfd7a1c8ed9ab93d8bfbfd5
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -96,13 +96,13 @@ F src/attach.c b18ba42c77f7d3941f5d23d2ca20fa1d841a4e91
 F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627
 F src/bitvec.c ab50c4b8c6a899dae499f5a805eebe4223c78269
 F src/btmutex.c 483ced3c52205b04b97df69161fadbf87f4f1ea2
-F src/btree.c a7b1ffdde06b8e854076789e393b315ee7856ae5
+F src/btree.c bae7f135dad8fd72ac41ce3c13b7b7ba9fe4d056
 F src/btree.h b1bd7e0b8c2e33658aaf447cb0d1d94f74664b6b
 F src/btreeInt.h 02325f04758dba0fcd0c08ac55cd9b189dad61a5
 F src/build.c 88cc5501a87f72d0538b040001d88d31f994edea
 F src/callback.c 77b302b0d41468dcda78c70e706e5b84577f0fa0
 F src/complete.c cb14e06dbe79dee031031f0d9e686ff306afe07c
-F src/date.c bbc4114d1b946d6a94d060bc5b9edce7142c6086
+F src/date.c e841168e5520bbbb2a1cbcdce7531d8b23017b4d
 F src/delete.c d3fc5987f2eb88f7b9549d58a5dfea079a83fe8b
 F src/expr.c ecb3b23d3543427cba3e2ac12a6c6ae4bb20d39b
 F src/fault.c 1f6177188edb00641673e462f3fab8cba9f7422b
@@ -114,44 +114,44 @@ F src/hwtime.h 745961687a65ef8918cd551c02e5ccb4b8e772de
 F src/insert.c c2ead6c36566de8e3f130e7ab1431723a269d5d7
 F src/journal.c cffd2cd214e58c0e99c3ff632b3bee6c7cbb260e
 F src/legacy.c 3626c71fb70912abec9a4312beba753a9ce800df
-F src/loadext.c f99a75534a53e281fa2461239ee4a4b4bf6ad564
-F src/main.c 34c9d9f99e0c6df25ac9d6e1a9c0964d8170cbe2
-F src/malloc.c 7b622d22f29e3be56d271a5a921f3b5788330189
+F src/loadext.c 2ac671f42a8ce15e2a58155b9d7f6c61eb7e127e
+F src/main.c 619caedf25329b55fe138e581497ec5052bb7e34
+F src/malloc.c 6f84f295db49a79c1e2fc07a63311f5685d47274
 F src/md5.c 008216bbb5d34c6fbab5357aa68575ad8a31516a
 F src/mem1.c 159f10e280f2d9aea597cf938851e61652dd5c3d
-F src/mem2.c 594270b8f0ed6c09ae5fb729eca2864139f9e293
-F src/mem3.c 617c2e2a72a10ecc5c01af14efc8c2596d2c2e87
-F src/mem4.c 45c328ec6dcb7e8d319cb383615b5fe547ca5409
-F src/mem5.c 3d2ff00c6e3bc37f5d82cd82e1a123b246fb7b39
-F src/mutex.c 890b83ccf19de17e88b612b2b3f18009a9f1bfa1
+F src/mem2.c 468a7fd5e0ce1909cfb554d7589af1d4a61f14bb
+F src/mem3.c 28b4812b87470a00b11821fb5850e7cabcce06c6
+F src/mem4.c 6703adb1717b26d9d70a1c2586b4b7b7ffee7909
+F src/mem5.c ad31a0a481b86b86f4ac0b6d952e69727d4e113a
+F src/mutex.c bcd07a29039b192c59117a5eb08fce208fe7d5aa
 F src/mutex.h b9b9baf7050f3bb1c723e1d22088a704783a2927
 F src/mutex_os2.c b8c1231319e966875f251a7ec137bea353546b87
 F src/mutex_unix.c 469a35c105435794375d683f75cad9e848817d19
 F src/mutex_w32.c e03baa369c5e8e7ea4dd2e5b3d098e047f7a2f06
-F src/os.c cf7e09d4215f35fc8269f0fa99f03fd2c2978658
+F src/os.c e9f37351dc4aacc4861f0adbe463f21c8f5969fa
 F src/os.h c9a7f94e80193fd4cf27f5c5698eb56753f1b05a
 F src/os_common.h 24525d8b7bce66c374dfc1810a6c9043f3359b60
 F src/os_os2.c 9f74147f1899793a106827f6bc770363ec377912
-F src/os_unix.c dd4a7b19ec00869764c389560c3faf566cf98a71
+F src/os_unix.c b8c07b0cd85c9909000740dc3f29ce938091b00c
 F src/os_win.c 0b90d9a1ce18bfd2a5f3c4a6bdb13ec369c805a9
-F src/pager.c 124b3eaed1bcf9d19b183b5796fa94e292f8cdb8
+F src/pager.c 2f5f55a9405a17240adede9e3b671778fb9a4978
 F src/pager.h 6aa3050a3c684475a5a9dbad5ff1cebad612acba
 F src/parse.y 8c2c3145eebe1964eb279cb3c4e502eae28bb0fa
 F src/pragma.c 70e7c865dce85fdf9df81848af2169009a56ed08
 F src/prepare.c 3c19149e75fbf3b08471a389f064da7302cad9c5
 F src/printf.c 8b063da9dcde26b7c500a01444b718d86f21bc6e
-F src/random.c 2b2db2de4ab491f5a14d3480466f8f4b5a5db74a
+F src/random.c 362b62e26db90ec9296903377a9d74b4669aa515
 F src/select.c 669687459e7d0193c89de06c5dbed55b4a41191c
 F src/shell.c a12ea645271b7876c8f080146f48e20b00d367ec
 F src/sqlite.h.in 48a3a643fa711141cb53b1c714be74098770e224
 F src/sqlite3ext.h faacd0e6a81aabee0861c6d7883c9172e74ef5b3
-F src/sqliteInt.h 90dff45c2fa188ff8763dd5358f7b1040e1bb4fb
+F src/sqliteInt.h 24fe828d52f497d4c026ea3b5f6a01d97ea01a2d
 F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8
 F src/table.c 1fa8f8113ac9cbc09ae4801c6d2a7f0af82c5822
 F src/tclsqlite.c 4dd9ee4cb44846ad9bcc4d0da8088c1e7d4b33d9
 F src/test1.c 736be7dea5cc126356bbb61a4b1ac5ff4fac7994
 F src/test2.c c46d146019ab6e37474e66b3c789e5237d9ea7b7
-F src/test3.c b5c1d1047a45af03375d66b3eec603faafa3ddc6
+F src/test3.c 01ff03164cf6a2bededa3b44ecd481603e2644fc
 F src/test4.c c2c0f5dc907f1346f5d4b65eb5799f11eb9e4071
 F src/test5.c 3a6a5717a149d7ca2e6d14f5be72cf7555d54dc4
 F src/test6.c 0a0304a69cfa4962a429d084c6d451ff9e4fb572
@@ -168,7 +168,7 @@ F src/test_hexio.c 2f1122aa3f012fa0142ee3c36ce5c902a70cd12f
 F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8
 F src/test_malloc.c 5c2c698355613d321f216ece25901be1040cc1fb
 F src/test_md5.c 28209a4e2068711b5443c33104fe41f21d160071
-F src/test_mutex.c f3e1f04fd6a42f9e7ff47784db8bc81e497b5c65
+F src/test_mutex.c 08640d7547bfadb6997a22d72e63914feaf4bc4f
 F src/test_onefile.c 1f87d4a21cbfb24a7c35e4333fa0bd34d641f68d
 F src/test_osinst.c 867f1317bd135f942a63eab5a78da40fc70d1493
 F src/test_schema.c e3f93725f7c5b2cff84a69dc4332040dfbc8f81a
@@ -184,7 +184,7 @@ F src/vacuum.c 14eb21b480924d87e791cd8ab6fb35ac563243ef
 F src/vdbe.c f6866986de706b98c2738040bc65907728650e8d
 F src/vdbe.h 1e3722d471739c2b213c6283b60373290e52f7ea
 F src/vdbeInt.h de321b2c02593e1420106634ed1f5a7d77ad35a7
-F src/vdbeapi.c 22b01ed175e4d4c613ee82cabc7a44a275641206
+F src/vdbeapi.c 9cf3207a58e484c74c60d61ac037c1cad8aa5b65
 F src/vdbeaux.c 09d7a6923d4d71d7028e0d72b9d146d3ece6054e
 F src/vdbeblob.c 9345f6dcd675fdcfdb537d2d2f487542d9ea136a
 F src/vdbefifo.c c46dae1194e4277bf007144d7e5b0c0b1c24f136
@@ -416,7 +416,8 @@ F test/misc5.test 0b68dcb630d44af2dbcdca94dd2b17c8d580f6fa
 F test/misc6.test 953cc693924d88e6117aeba16f46f0bf5abede91
 F test/misc7.test 26e0d948a413bca61ed031159907a03d64647409
 F test/misuse.test 30b3a458e5a70c31e74c291937b6c82204c59f33
-F test/mutex1.test 6494fe9e6747328a0b1b0d2676ff4cf1a12fb51d
+F test/mutex1.test c8de096af7ae7ccee2b8f472fecb224b214e24d0
+F test/mutex2.test 6c8f4a5425a27088bc2ad107c71b7abbc2d8534d
 F test/nan.test 14c41572ff52dbc740b1c3303dd313a90dc6084c
 F test/notnull.test 44d600f916b770def8b095a9962dbe3be5a70d82
 F test/null.test a8b09b8ed87852742343b33441a9240022108993
@@ -432,7 +433,7 @@ F test/pragma2.test 5364893491b9231dd170e3459bfc2e2342658b47
 F test/printf.test c3405535b418d454e8a52196a0fc592ec9eec58d
 F test/progress.test 5b075c3c790c7b2a61419bc199db87aaf48b8301 x
 F test/ptrchng.test 83150cb7b513e33cce90fdc68f4b1817551857c0
-F test/quick.test ebd2ed55075fadf8a44f4e64372091c7bc85e32d
+F test/quick.test 58a082b4cd30ed7d5a06129a6b1ec2550610806b
 F test/quote.test 215897dbe8de1a6f701265836d6601cc6ed103e6
 F test/rdonly.test b34db316525440d3b42c32e83942c02c37d28ef0
 F test/reindex.test 38b138abe36bf9a08c791ed44d9f76cd6b97b78b
@@ -548,7 +549,7 @@ F test/vacuum.test 0bc75ee74ab9c69322d6563aa2287375697e630b
 F test/vacuum2.test d3b9691541fe6ed5c711f547a1c7d70e9760ac6f
 F test/vacuum3.test 6149b24613f487915ca9cedfbb9147d5759714ec
 F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102
-F test/veryquick.test c08b303a9a6e5bbb27d0988858e919f3b70042aa
+F test/veryquick.test 5117ca7a26f3c86abd5bd34590a82bbccbd79d34
 F test/view.test 4864e3841ab3213a95297718b94d5d6a8d3bc78b
 F test/vtab1.test 47092e3ac59141f08e09a6c0cc0df8997242bc79
 F test/vtab2.test 1da49b015582965a8fc386aa23d051a5a622b08e
@@ -596,7 +597,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P c3c7bfc9db6774824be14a1394e1842716dce8ec
-R 03ee4502eba907b49b63dcad3c223959
-U drh
-Z 84afc1583f0d4ac82122bd3650c7f8b5
+P 70c6739f4e84b3433e14960346b54d0e9e0bb9c6
+R bcb69678a02b2561df6a33f19115dfbd
+U danielk1977
+Z b2748b102e9ea5fd93fb45dc8d5bd3c0
index a733e649ba3791028c3a12865a692e8a8b16e469..62e981587431a99db4e11dcdbdd934a9613a833c 100644 (file)
@@ -1 +1 @@
-70c6739f4e84b3433e14960346b54d0e9e0bb9c6
\ No newline at end of file
+5059644c4bc5f6679afd939e0bc26080f42a9918
\ No newline at end of file
index be003249c0465010c6008df2f466b5bf67d94af4..3e3beb3273e2aa2cdaaad8543d6f65155722e3f3 100644 (file)
@@ -9,7 +9,7 @@
 **    May you share freely, never taking more than you give.
 **
 *************************************************************************
-** $Id: btree.c,v 1.465 2008/06/17 15:12:01 drh Exp $
+** $Id: btree.c,v 1.466 2008/06/18 17:09:10 danielk1977 Exp $
 **
 ** This file implements a external (disk-based) database using BTrees.
 ** See the header comment on "btreeInt.h" for additional information.
@@ -1201,7 +1201,7 @@ int sqlite3BtreeOpen(
         return SQLITE_NOMEM;
       }
       sqlite3OsFullPathname(pVfs, zFilename, nFullPathname, zFullPathname);
-      mutexShared = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
+      mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
       sqlite3_mutex_enter(mutexShared);
       for(pBt=sqlite3SharedCacheList; pBt; pBt=pBt->pNext){
         assert( pBt->nRef>0 );
@@ -1298,9 +1298,9 @@ int sqlite3BtreeOpen(
     if( p->sharable ){
       sqlite3_mutex *mutexShared;
       pBt->nRef = 1;
-      mutexShared = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
-      if( SQLITE_THREADSAFE ){
-        pBt->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
+      mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
+      if( SQLITE_THREADSAFE && sqlite3Config.bCoreMutex ){
+        pBt->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_FAST);
         if( pBt->mutex==0 ){
           rc = SQLITE_NOMEM;
           db->mallocFailed = 0;
@@ -1373,7 +1373,7 @@ static int removeFromSharingList(BtShared *pBt){
   int removed = 0;
 
   assert( sqlite3_mutex_notheld(pBt->mutex) );
-  pMaster = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
+  pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
   sqlite3_mutex_enter(pMaster);
   pBt->nRef--;
   if( pBt->nRef<=0 ){
index c698eb92edf85603bdb8e41dfc1a96e7f6b57d75..566c5362c2795a33e695ea603ac3af94d4232b52 100644 (file)
@@ -16,7 +16,7 @@
 ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
 ** All other code has file scope.
 **
-** $Id: date.c,v 1.84 2008/06/15 02:51:47 drh Exp $
+** $Id: date.c,v 1.85 2008/06/18 17:09:10 danielk1977 Exp $
 **
 ** SQLite processes all times and dates as Julian Day numbers.  The
 ** dates and times are stored as the number of days since noon
@@ -474,7 +474,7 @@ static int localtimeOffset(DateTime *p){
 #else
   {
     struct tm *pTm;
-    sqlite3_mutex_enter(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER));
+    sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
     pTm = localtime(&t);
     y.Y = pTm->tm_year + 1900;
     y.M = pTm->tm_mon + 1;
@@ -482,7 +482,7 @@ static int localtimeOffset(DateTime *p){
     y.h = pTm->tm_hour;
     y.m = pTm->tm_min;
     y.s = pTm->tm_sec;
-    sqlite3_mutex_leave(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER));
+    sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
   }
 #endif
   y.validYMD = 1;
@@ -1031,10 +1031,10 @@ static void currentTimeFunc(
 #else
   {
     struct tm *pTm;
-    sqlite3_mutex_enter(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER));
+    sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
     pTm = gmtime(&t);
     strftime(zBuf, 20, zFormat, pTm);
-    sqlite3_mutex_leave(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER));
+    sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
   }
 #endif
 
index 828d71ef89bd98e859cbf988f43ad67343901425..a045d1302f89a07f9fdfdfbc4b4286823139c5b3 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains code used to dynamically load extensions into
 ** the SQLite library.
 **
-** $Id: loadext.c,v 1.48 2008/06/13 18:24:27 drh Exp $
+** $Id: loadext.c,v 1.49 2008/06/18 17:09:10 danielk1977 Exp $
 */
 
 #ifndef SQLITE_CORE
@@ -478,7 +478,7 @@ int sqlite3_auto_extension(void *xInit){
   {
     int i;
 #ifndef SQLITE_MUTEX_NOOP
-    sqlite3_mutex *mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
+    sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
 #endif
     sqlite3_mutex_enter(mutex);
     for(i=0; i<autoext.nExt; i++){
@@ -511,7 +511,7 @@ void sqlite3_reset_auto_extension(void){
 #endif
   {
 #ifndef SQLITE_MUTEX_NOOP
-    sqlite3_mutex *mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
+    sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
 #endif
     sqlite3_mutex_enter(mutex);
     sqlite3_free(autoext.aExt);
@@ -537,7 +537,7 @@ int sqlite3AutoLoadExtensions(sqlite3 *db){
   for(i=0; go; i++){
     char *zErrmsg = 0;
 #ifndef SQLITE_MUTEX_NOOP
-    sqlite3_mutex *mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
+    sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
 #endif
     sqlite3_mutex_enter(mutex);
     if( i>=autoext.nExt ){
index c3c57abda7be57fba170e8c71e09c6a441284547..d77b5b599abf87590ef3bd2b9359e84574093e54 100644 (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.448 2008/06/18 13:27:47 drh Exp $
+** $Id: main.c,v 1.449 2008/06/18 17:09:10 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -76,7 +76,7 @@ int sqlite3_initialize(void){
   if( sqlite3IsInit ) return SQLITE_OK;
   rc = sqlite3_mutex_init();
   if( rc==SQLITE_OK ){
-    sqlite3_mutex *pMutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
+    sqlite3_mutex *pMutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
     sqlite3_mutex_enter(pMutex);
     if( sqlite3IsInit==0 ){
       sqlite3IsInit = 1;
@@ -1208,11 +1208,13 @@ static int openDatabase(
   /* Allocate the sqlite data structure */
   db = sqlite3MallocZero( sizeof(sqlite3) );
   if( db==0 ) goto opendb_out;
-  db->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_RECURSIVE);
-  if( db->mutex==0 ){
-    sqlite3_free(db);
-    db = 0;
-    goto opendb_out;
+  if( sqlite3Config.bFullMutex ){
+    db->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE);
+    if( db->mutex==0 ){
+      sqlite3_free(db);
+      db = 0;
+      goto opendb_out;
+    }
   }
   sqlite3_mutex_enter(db->mutex);
   db->errMask = 0xff;
@@ -1363,7 +1365,7 @@ static int openDatabase(
 
 opendb_out:
   if( db ){
-    assert( db->mutex!=0 );
+    assert( db->mutex!=0 || sqlite3Config.bFullMutex==0 );
     sqlite3_mutex_leave(db->mutex);
   }
   if( SQLITE_NOMEM==(rc = sqlite3_errcode(db)) ){
index 7db0eacc39d23c388947dec5a5c870796f2c8ee7..cdfd6a9eae225a45df47e0f09a90324e50fca141 100644 (file)
@@ -12,7 +12,7 @@
 **
 ** Memory allocation functions used throughout sqlite.
 **
-** $Id: malloc.c,v 1.18 2008/06/17 15:12:01 drh Exp $
+** $Id: malloc.c,v 1.19 2008/06/18 17:09:10 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include <stdarg.h>
@@ -102,8 +102,8 @@ int sqlite3MallocInit(void){
     sqlite3MemSetDefault();
   }
   memset(&mem0, 0, sizeof(mem0));
-  if( sqlite3Config.bMemstat && sqlite3Config.bCoreMutex ){
-    mem0.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MEM);
+  if( sqlite3Config.bMemstat ){
+    mem0.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
   }
   return sqlite3Config.m.xInit(sqlite3Config.m.pAppData);
 }
index 4f97ba2cecc9298f44f1aaf80506a0f1c84f1b68..2400ce0ba1c729f68cd8904b097b0838ced7b756 100644 (file)
@@ -19,7 +19,7 @@
 ** This file contains implementations of the low-level memory allocation
 ** routines specified in the sqlite3_mem_methods object.
 **
-** $Id: mem2.c,v 1.31 2008/06/17 17:21:18 danielk1977 Exp $
+** $Id: mem2.c,v 1.32 2008/06/18 17:09:10 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 
@@ -162,7 +162,7 @@ static int sqlite3MemSize(void *p){
 ** Initialize the memory allocation subsystem.
 */
 static int sqlite3MemInit(void *NotUsed){
-  mem.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
+  mem.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
   return SQLITE_OK;
 }
 
index e74cb8f036fc14242a66b2bef7604e7791fcc8bd..fc263ee2268473cfe971a6b19fcae866d75c47c2 100644 (file)
@@ -20,7 +20,7 @@
 ** This version of the memory allocation subsystem is used if
 ** and only if SQLITE_MEMORY_SIZE is defined.
 **
-** $Id: mem3.c,v 1.13 2008/06/13 18:24:27 drh Exp $
+** $Id: mem3.c,v 1.14 2008/06/18 17:09:10 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 
@@ -214,7 +214,7 @@ static void memsys3Link(u32 i){
 */
 static void memsys3Enter(void){
   if( mem.mutex==0 ){
-    mem.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MEM);
+    mem.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
     mem.aPool[0].u.hdr.size4x = SQLITE_MEMORY_SIZE/2 + 2;
     mem.aPool[SQLITE_MEMORY_SIZE/8].u.hdr.prevSize = SQLITE_MEMORY_SIZE/8;
     mem.aPool[SQLITE_MEMORY_SIZE/8].u.hdr.size4x = 1;
index 39180b5f5922a298a9158b6a9418ea90e2e70649..5a7809856196363cf6948edc901f611c62ec175b 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains the C functions that implement a memory
 ** allocation subsystem for use by SQLite.  
 **
-** $Id: mem4.c,v 1.2 2008/02/14 23:26:56 drh Exp $
+** $Id: mem4.c,v 1.3 2008/06/18 17:09:10 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 
@@ -112,7 +112,7 @@ static struct {
 */
 static void memsys4Enter(void){
   if( mem.mutex==0 ){
-    mem.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MEM);
+    mem.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
   }
   sqlite3_mutex_enter(mem.mutex);
 }
index fbea0ef8983010f69d941fbcbbf8a04a36915539..198b0743e4ba9fdea61c8d2d5d02befaf76cf938 100644 (file)
@@ -20,7 +20,7 @@
 ** This version of the memory allocation subsystem is used if
 ** and only if SQLITE_POW2_MEMORY_SIZE is defined.
 **
-** $Id: mem5.c,v 1.5 2008/06/13 18:24:27 drh Exp $
+** $Id: mem5.c,v 1.6 2008/06/18 17:09:10 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 
@@ -193,7 +193,7 @@ static void memsys5Enter(void){
     assert( sizeof(Mem5Block)==POW2_MIN );
     assert( (SQLITE_POW2_MEMORY_SIZE % POW2_MAX)==0 );
     assert( SQLITE_POW2_MEMORY_SIZE>=POW2_MAX );
-    mem.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MEM);
+    mem.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
     sqlite3_mutex_enter(mem.mutex);
     for(i=0; i<NSIZE; i++) mem.aiFreelist[i] = -1;
     for(i=0; i<=NBLOCK-SZ_MAX; i += SZ_MAX){
index a9fe68fa782f226d2d599e4016fec96517b23a00..1b399a40d888d91730955f9234bba8a070397681 100644 (file)
@@ -19,7 +19,7 @@
 ** implementation is suitable for testing.
 ** debugging purposes
 **
-** $Id: mutex.c,v 1.23 2008/06/18 09:45:56 danielk1977 Exp $
+** $Id: mutex.c,v 1.24 2008/06/18 17:09:10 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 
 ** Initialize the mutex system.
 */
 int sqlite3_mutex_init(void){ 
-  int rc;
-  if( !sqlite3Config.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 sqlite3Config structure.
-    **
-    ** The danger is that although sqlite3_config() is not a threadsafe
-    ** API, sqlite3_initialize() is, and so multiple threads may be
-    ** attempting to run this function simultaneously. To guard write
-    ** access to the sqlite3Config structure, the 'MASTER' static mutex
-    ** is obtained before modifying it.
-    */
-    sqlite3_mutex_methods *p = sqlite3DefaultMutex();
-    sqlite3_mutex *pMaster;
-
-    rc = p->xMutexInit();
-    if( rc==SQLITE_OK ){
-      pMaster = p->xMutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
-      assert(pMaster);
-      p->xMutexEnter(pMaster);
-      assert( sqlite3Config.mutex.xMutexAlloc==0 
-           || sqlite3Config.mutex.xMutexAlloc==p->xMutexAlloc
-      );
-      if( !sqlite3Config.mutex.xMutexAlloc ){
-        sqlite3Config.mutex = *p;
+  int rc = SQLITE_OK;
+  if( sqlite3Config.bCoreMutex ){
+    if( !sqlite3Config.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 sqlite3Config structure.
+      **
+      ** The danger is that although sqlite3_config() is not a threadsafe
+      ** API, sqlite3_initialize() is, and so multiple threads may be
+      ** attempting to run this function simultaneously. To guard write
+      ** access to the sqlite3Config structure, the 'MASTER' static mutex
+      ** is obtained before modifying it.
+      */
+      sqlite3_mutex_methods *p = sqlite3DefaultMutex();
+      sqlite3_mutex *pMaster = 0;
+  
+      rc = p->xMutexInit();
+      if( rc==SQLITE_OK ){
+        pMaster = p->xMutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
+        assert(pMaster);
+        p->xMutexEnter(pMaster);
+        assert( sqlite3Config.mutex.xMutexAlloc==0 
+             || sqlite3Config.mutex.xMutexAlloc==p->xMutexAlloc
+        );
+        if( !sqlite3Config.mutex.xMutexAlloc ){
+          sqlite3Config.mutex = *p;
+        }
+        p->xMutexLeave(pMaster);
       }
-      p->xMutexLeave(pMaster);
+    }else{
+      rc = sqlite3Config.mutex.xMutexInit();
     }
-  }else{
-    rc = sqlite3Config.mutex.xMutexInit();
   }
 
   return rc;
@@ -81,6 +83,13 @@ sqlite3_mutex *sqlite3_mutex_alloc(int id){
   return sqlite3Config.mutex.xMutexAlloc(id);
 }
 
+sqlite3_mutex *sqlite3MutexAlloc(int id){
+  if( !sqlite3Config.bCoreMutex ){
+    return 0;
+  }
+  return sqlite3Config.mutex.xMutexAlloc(id);
+}
+
 /*
 ** Free a dynamic mutex.
 */
index 216002986881c9dc4866c2f3cf869be18082e91c..b50fdd56176c42b8197907f20be1e5ee84b7880e 100644 (file)
--- a/src/os.c
+++ b/src/os.c
@@ -13,7 +13,7 @@
 ** This file contains OS interface code that is common to all
 ** architectures.
 **
-** $Id: os.c,v 1.113 2008/06/15 02:51:48 drh Exp $
+** $Id: os.c,v 1.114 2008/06/18 17:09:10 danielk1977 Exp $
 */
 #define _SQLITE_OS_C_ 1
 #include "sqliteInt.h"
@@ -207,7 +207,7 @@ sqlite3_vfs *sqlite3_vfs_find(const char *zVfs){
   if( rc ) return 0;
 #endif
 #ifndef SQLITE_MUTEX_NOOP
-  mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
+  mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
 #endif
   sqlite3_vfs *pVfs = 0;
   static int isInit = 0;
@@ -228,7 +228,7 @@ sqlite3_vfs *sqlite3_vfs_find(const char *zVfs){
 ** Unlink a VFS from the linked list
 */
 static void vfsUnlink(sqlite3_vfs *pVfs){
-  assert( sqlite3_mutex_held(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER)) );
+  assert( sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)) );
   if( pVfs==0 ){
     /* No-op */
   }else if( vfsList==pVfs ){
@@ -258,7 +258,7 @@ int sqlite3_vfs_register(sqlite3_vfs *pVfs, int makeDflt){
   if( rc ) return rc;
 #endif
 #ifndef SQLITE_MUTEX_NOOP
-  mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
+  mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
 #endif
   sqlite3_vfs_find(0);  /* Make sure we are initialized */
   sqlite3_mutex_enter(mutex);
@@ -280,7 +280,7 @@ int sqlite3_vfs_register(sqlite3_vfs *pVfs, int makeDflt){
 */
 int sqlite3_vfs_unregister(sqlite3_vfs *pVfs){
 #ifndef SQLITE_MUTEX_NOOP
-  sqlite3_mutex *mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
+  sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
 #endif
   sqlite3_mutex_enter(mutex);
   vfsUnlink(pVfs);
index 9b5533983650ca2e403e416744331e993ee1667c..906e4b6359b7f2770024ae28040a580cc7bf4f7a 100644 (file)
@@ -12,7 +12,7 @@
 **
 ** This file contains code that is specific to Unix systems.
 **
-** $Id: os_unix.c,v 1.187 2008/06/13 18:24:27 drh Exp $
+** $Id: os_unix.c,v 1.188 2008/06/18 17:09:10 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #if OS_UNIX              /* This file is used on unix only */
@@ -367,10 +367,10 @@ typedef enum {
 ** Helper functions to obtain and relinquish the global mutex.
 */
 static void enterMutex(){
-  sqlite3_mutex_enter(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER));
+  sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
 }
 static void leaveMutex(){
-  sqlite3_mutex_leave(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER));
+  sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
 }
 
 #if SQLITE_THREADSAFE
index b1e08e848af8e8c3a62f0754e477cd6d2b33b23b..7cdb20860d0a13e3528e355b3f3030c3979c6f08 100644 (file)
@@ -18,7 +18,7 @@
 ** file simultaneously, or one process from reading the database while
 ** another is writing.
 **
-** @(#) $Id: pager.c,v 1.458 2008/06/17 15:12:01 drh Exp $
+** @(#) $Id: pager.c,v 1.459 2008/06/18 17:09:10 danielk1977 Exp $
 */
 #ifndef SQLITE_OMIT_DISKIO
 #include "sqliteInt.h"
@@ -518,7 +518,7 @@ static const unsigned char aJournalMagic[] = {
     if( p->iInUseMM && p->iInUseDB==1 ){
 #ifndef SQLITE_MUTEX_NOOP
       sqlite3_mutex *mutex;
-      mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MEM2);
+      mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM2);
 #endif
       p->iInUseDB = 0;
       sqlite3_mutex_enter(mutex);
@@ -616,9 +616,9 @@ static void lruListAdd(PgHdr *pPg){
   listAdd(&pPg->pPager->lru, &pPg->free, pPg);
 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
   if( !pPg->pPager->memDb ){
-    sqlite3_mutex_enter(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU));
+    sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_LRU));
     listAdd(&sqlite3LruPageList, &pPg->gfree, pPg);
-    sqlite3_mutex_leave(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU));
+    sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_LRU));
   }
 #endif
 }
@@ -632,9 +632,9 @@ static void lruListRemove(PgHdr *pPg){
   listRemove(&pPg->pPager->lru, &pPg->free, pPg);
 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
   if( !pPg->pPager->memDb ){
-    sqlite3_mutex_enter(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU));
+    sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_LRU));
     listRemove(&sqlite3LruPageList, &pPg->gfree, pPg);
-    sqlite3_mutex_leave(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU));
+    sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_LRU));
   }
 #endif
 }
@@ -651,11 +651,11 @@ static void lruListSetFirstSynced(Pager *pPager){
 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
   if( !pPager->memDb ){
     PgHdr *p;
-    sqlite3_mutex_enter(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU));
+    sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_LRU));
     for(p=sqlite3LruPageList.pFirst; p && p->needSync; p=p->gfree.pNext);
     assert(p==pPager->lru.pFirstSynced || p==sqlite3LruPageList.pFirstSynced);
     sqlite3LruPageList.pFirstSynced = p;
-    sqlite3_mutex_leave(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU));
+    sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_LRU));
   }
 #endif
 }
@@ -2364,7 +2364,7 @@ int sqlite3PagerOpen(
   pPager->iInUseDB = 0;
   if( !memDb ){
 #ifndef SQLITE_MUTEX_NOOP
-    sqlite3_mutex *mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MEM2);
+    sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM2);
 #endif
     sqlite3_mutex_enter(mutex);
     pPager->pNext = sqlite3PagerList;
@@ -2751,7 +2751,7 @@ int sqlite3PagerClose(Pager *pPager){
 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
   if( !MEMDB ){
 #ifndef SQLITE_MUTEX_NOOP
-    sqlite3_mutex *mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MEM2);
+    sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM2);
 #endif
     sqlite3_mutex_enter(mutex);
     if( pPager->pPrev ){
@@ -3278,7 +3278,7 @@ int sqlite3PagerReleaseMemory(int nReq){
   */
 #ifndef SQLITE_MUTEX_NOOP
   sqlite3_mutex *mutex;       /* The MEM2 mutex */
-  mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MEM2);
+  mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM2);
 #endif
   sqlite3_mutex_enter(mutex);
 
@@ -3296,7 +3296,7 @@ int sqlite3PagerReleaseMemory(int nReq){
     /* Try to find a page to recycle that does not require a sync(). If
     ** this is not possible, find one that does require a sync().
     */
-    sqlite3_mutex_enter(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU));
+    sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_LRU));
     pPg = sqlite3LruPageList.pFirstSynced;
     while( pPg && (pPg->needSync || pPg->pPager->iInUseDB) ){
       pPg = pPg->gfree.pNext;
@@ -3307,7 +3307,7 @@ int sqlite3PagerReleaseMemory(int nReq){
         pPg = pPg->gfree.pNext;
       }
     }
-    sqlite3_mutex_leave(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU));
+    sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_LRU));
 
     /* If pPg==0, then the block above has failed to find a page to
     ** recycle. In this case return early - no further memory will
index 4b977f2b46410a04e734051cfc0eb59897185b0c..f3741c32eb5ce5841a0bf3d0651444c0434c053b 100644 (file)
@@ -15,7 +15,7 @@
 ** Random numbers are used by some of the database backends in order
 ** to generate random integer keys for tables or random filenames.
 **
-** $Id: random.c,v 1.23 2008/03/21 16:45:47 drh Exp $
+** $Id: random.c,v 1.24 2008/06/18 17:09:10 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 
@@ -92,10 +92,7 @@ static int randomByte(void){
 */
 void sqlite3_randomness(int N, void *pBuf){
   unsigned char *zBuf = pBuf;
-  static sqlite3_mutex *mutex = 0;
-  if( mutex==0 ){
-    mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_PRNG);
-  }
+  sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG);
   sqlite3_mutex_enter(mutex);
   while( N-- ){
     *(zBuf++) = randomByte();
index b55cfd3ee45bd1e25bfa0076119222def7d496b2..74ed0222803ef20519efdd09a3aa810adc62b864 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** Internal interface definitions for SQLite.
 **
-** @(#) $Id: sqliteInt.h,v 1.713 2008/06/18 13:27:47 drh Exp $
+** @(#) $Id: sqliteInt.h,v 1.714 2008/06/18 17:09:10 danielk1977 Exp $
 */
 #ifndef _SQLITEINT_H_
 #define _SQLITEINT_H_
@@ -1806,6 +1806,7 @@ void sqlite3PageFree(void*);
 void sqlite3MemSetDefault(void);
 
 sqlite3_mutex_methods *sqlite3DefaultMutex(void);
+sqlite3_mutex *sqlite3MutexAlloc(int);
 
 int sqlite3IsNaN(double);
 
index f2381f41ec5f9900e5be90588bf0368e2b805545..0726b5863042dc1aedf932e01a01ef45fc387b41 100644 (file)
@@ -13,7 +13,7 @@
 ** is not included in the SQLite library.  It is used for automated
 ** testing of the SQLite library.
 **
-** $Id: test3.c,v 1.97 2008/06/06 11:11:26 danielk1977 Exp $
+** $Id: test3.c,v 1.98 2008/06/18 17:09:10 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include "btreeInt.h"
@@ -78,7 +78,7 @@ static int btree_open(
   nRefSqlite3++;
   if( nRefSqlite3==1 ){
     sDb.pVfs = sqlite3_vfs_find(0);
-    sDb.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_RECURSIVE);
+    sDb.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE);
     sqlite3_mutex_enter(sDb.mutex);
   }
   rc = sqlite3BtreeOpen(argv[1], &sDb, &pBt, flags,
index fac9f41297d352bbbdd402b6f68c885f9a7e29cd..0becbee3061628755447f91c0ca55b3ecca8db98 100644 (file)
@@ -10,7 +10,7 @@
 **
 *************************************************************************
 ** 
-** $Id: test_mutex.c,v 1.1 2008/06/18 09:45:56 danielk1977 Exp $
+** $Id: test_mutex.c,v 1.2 2008/06/18 17:09:10 danielk1977 Exp $
 */
 
 #include "tcl.h"
@@ -247,6 +247,42 @@ static int test_clear_mutex_counters(
   return TCL_OK;
 }
 
+/*
+** sqlite3_config OPTION
+*/
+static int test_config(
+  void * clientData,
+  Tcl_Interp *interp,
+  int objc,
+  Tcl_Obj *CONST objv[]
+){
+  struct ConfigOption {
+    const char *zName;
+    int iValue;
+  } aOpt[] = {
+    {"singlethread", SQLITE_CONFIG_SINGLETHREAD},
+    {"multithread",  SQLITE_CONFIG_MULTITHREAD},
+    {"serialized",   SQLITE_CONFIG_SERIALIZED},
+    {0, 0}
+  };
+  int s = sizeof(struct ConfigOption);
+  int i;
+  int rc;
+
+  if( objc!=2 ){
+    Tcl_WrongNumArgs(interp, 1, objv, "");
+    return TCL_ERROR;
+  }
+
+  if( Tcl_GetIndexFromObjStruct(interp, objv[1], aOpt, s, "flag", 0, &i) ){
+    return TCL_ERROR;
+  }
+
+  rc = sqlite3_config(aOpt[i].iValue);
+  Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);
+  return TCL_OK;
+}
+
 int Sqlitetest_mutex_Init(Tcl_Interp *interp){
   static struct {
     char *zName;
@@ -254,6 +290,7 @@ int Sqlitetest_mutex_Init(Tcl_Interp *interp){
   } aCmd[] = {
     { "sqlite3_shutdown",        (Tcl_ObjCmdProc*)test_shutdown },
     { "sqlite3_initialize",      (Tcl_ObjCmdProc*)test_initialize },
+    { "sqlite3_config",          (Tcl_ObjCmdProc*)test_config },
 
     { "install_mutex_counters",  (Tcl_ObjCmdProc*)test_install_mutex_counters },
     { "read_mutex_counters",     (Tcl_ObjCmdProc*)test_read_mutex_counters },
index d9d4a93dbed998c5c35c7d2fb0954a97c35665b1..8fc3987c68ba0ac84fe54d69d94ad6b52675c77a 100644 (file)
@@ -13,7 +13,7 @@
 ** This file contains code use to implement APIs that are part of the
 ** VDBE.
 **
-** $Id: vdbeapi.c,v 1.132 2008/05/16 15:24:58 danielk1977 Exp $
+** $Id: vdbeapi.c,v 1.133 2008/06/18 17:09:10 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include "vdbeInt.h"
@@ -68,10 +68,10 @@ static int stmtLruCheck(){
 ** is protected by the SQLITE_MUTEX_STATIC_LRU mutex.
 */
 static void stmtLruAdd(Vdbe *p){
-  sqlite3_mutex_enter(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU2));
+  sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_LRU2));
 
   if( p->pLruPrev || p->pLruNext || sqlite3LruStatements.pFirst==p ){
-    sqlite3_mutex_leave(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU2));
+    sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_LRU2));
     return;
   }
 
@@ -90,7 +90,7 @@ static void stmtLruAdd(Vdbe *p){
 
   assert( stmtLruCheck() );
 
-  sqlite3_mutex_leave(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU2));
+  sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_LRU2));
 }
 
 /*
@@ -123,9 +123,9 @@ static void stmtLruRemoveNomutex(Vdbe *p){
 ** statement is not currently part of the list, this call is a no-op.
 */
 static void stmtLruRemove(Vdbe *p){
-  sqlite3_mutex_enter(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU2));
+  sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_LRU2));
   stmtLruRemoveNomutex(p);
-  sqlite3_mutex_leave(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU2));
+  sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_LRU2));
 }
 
 /*
@@ -137,7 +137,7 @@ int sqlite3VdbeReleaseMemory(int n){
   Vdbe *pNext;
   int nFree = 0;
 
-  sqlite3_mutex_enter(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU2));
+  sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_LRU2));
   for(p=sqlite3LruStatements.pFirst; p && nFree<n; p=pNext){
     pNext = p->pLruNext;
 
@@ -152,7 +152,7 @@ int sqlite3VdbeReleaseMemory(int n){
       sqlite3_mutex_leave(p->db->mutex);
     }
   }
-  sqlite3_mutex_leave(sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU2));
+  sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_LRU2));
 
   return nFree;
 }
index e8107ac6a920709b2ddcd12917a5255d72727457..b1c8dd1f3d9113829e2c364ccdc9a98d2103f735 100644 (file)
@@ -9,7 +9,7 @@
 #
 #***********************************************************************
 #
-# $Id: mutex1.test,v 1.1 2008/06/18 09:45:56 danielk1977 Exp $
+# $Id: mutex1.test,v 1.2 2008/06/18 17:09:10 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -75,8 +75,50 @@ do_test mutex1-1.9 {
   list $counters(total) $counters(static_master)
 } {0 0}
 
+#-------------------------------------------------------------------------
+# Tests mutex1-2.* test the three thread-safety related modes that
+# can be selected using sqlite3_config:
+#
+#   * Serialized mode,
+#   * Multi-threaded mode,
+#   * Single-threaded mode.
+#
+
+foreach {mode mutexes} {
+  singlethread {}
+  multithread  {fast static_master static_mem static_prng}
+  serialized   {fast recursive static_master static_mem static_prng}
+} {
+  do_test mutex1.2.$mode.1 {
+    catch {db close}
+    sqlite3_shutdown
+    sqlite3_config $mode
+  } SQLITE_OK
+
+  do_test mutex1.2.$mode.2 {
+    clear_mutex_counters
+    sqlite3 db test.db
+    catchsql { CREATE TABLE abc(a, b, c) }
+    db eval {
+      INSERT INTO abc VALUES(1, 2, 3);
+    }
+  } {}
+
+  do_test mutex1.2.$mode.3 {
+    mutex_counters counters
+
+    set res [list]
+    foreach {key value} [array get counters] {
+      if {$key ne "total" && $value > 0} {
+        lappend res $key
+      }
+    }
+    lsort $res
+  } $mutexes
+}
 
 do_test mutex1-X {
+  db close
   sqlite3_shutdown
   clear_mutex_counters
   install_mutex_counters 0
diff --git a/test/mutex2.test b/test/mutex2.test
new file mode 100644 (file)
index 0000000..86c7d9e
--- /dev/null
@@ -0,0 +1,72 @@
+# 2007 March 26
+#
+# The author disclaims copyright to this source code.  In place of
+# a legal notice, here is a blessing:
+#
+#    May you do good and not evil.
+#    May you find forgiveness for yourself and forgive others.
+#    May you share freely, never taking more than you give.
+#
+#***********************************************************************
+#
+# This file runs some other test files after calling sqlite3_config to
+# set the thread-safety mode to SQLITE_CONFIG_SINGLETHREAD and
+# SQLITE_CONFIG_MULTITHREAD (instead of the default SQLITE_CONFIG_SERIALIZED).
+#
+# $Id: mutex2.test,v 1.1 2008/06/18 17:09:10 danielk1977 Exp $
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+ifcapable {!pager_pragmas} {
+  finish_test
+  return
+}
+
+rename finish_test really_finish_test2
+proc finish_test {} {}
+set ISQUICK 1
+
+rename do_test really_do_test
+proc do_test {args} {
+  set sc [concat really_do_test "mutex2-${::thread_mode}.[lindex $args 0]" \
+      [lrange $args 1 end]]
+  eval $sc
+}
+
+foreach ::thread_mode {singlethread multithread} {
+  do_test mutex2-$::thread_mode.0 {
+    catch {db close}
+    sqlite3_shutdown
+    sqlite3_config $::thread_mode
+  } SQLITE_OK
+
+  source $testdir/delete.test
+  source $testdir/delete2.test
+  source $testdir/insert.test
+  source $testdir/rollback.test
+  source $testdir/select1.test
+  source $testdir/select2.test
+  source $testdir/trans.test
+  source $testdir/update.test
+  source $testdir/vacuum.test
+  source $testdir/types.test
+  source $testdir/types2.test
+  source $testdir/types3.test
+
+  #source $testdir/malloc.test
+  #source $testdir/ioerr.test
+}
+
+do_test mutex2-X {
+  catch {db close}
+  sqlite3_shutdown
+  sqlite3_config serialized
+} SQLITE_OK
+
+rename finish_test ""
+rename really_finish_test2 finish_test
+rename do_test ""
+rename really_do_test do_test
+finish_test
+
index bc368e84caf55bd1c1a751c1049f6a63d94ee7da..c30818f7ab9fe8b7afa0483b2245b87ed2d50645 100644 (file)
@@ -6,7 +6,7 @@
 #***********************************************************************
 # This file runs all tests.
 #
-# $Id: quick.test,v 1.78 2008/04/19 20:34:19 drh Exp $
+# $Id: quick.test,v 1.79 2008/06/18 17:09:10 danielk1977 Exp $
 
 proc lshift {lvar} {
   upvar $lvar l
@@ -64,6 +64,7 @@ set EXCLUDE {
   memleak.test
   misc7.test
   misuse.test
+  mutex2.test
   onefile.test
   quick.test
   soak.test
index f24c0ae829c13f3ee01e1e47d45240d8b0936c02..4cdb8d562bb9f074824bfd5417d235d201c19cfb 100644 (file)
@@ -6,7 +6,7 @@
 #***********************************************************************
 # This file runs all tests.
 #
-# $Id: veryquick.test,v 1.3 2008/04/19 20:34:19 drh Exp $
+# $Id: veryquick.test,v 1.4 2008/06/18 17:09:10 danielk1977 Exp $
 
 proc lshift {lvar} {
   upvar $lvar l
@@ -86,6 +86,7 @@ set EXCLUDE {
   memleak.test
   misc7.test
   misuse.test
+  mutex2.test
   onefile.test
   quick.test
   soak.test