]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Make sure the mutex is held while calling sqlite3ApiExit() in
authordrh <drh@noemail.net>
Mon, 3 May 2010 13:37:30 +0000 (13:37 +0000)
committerdrh <drh@noemail.net>
Mon, 3 May 2010 13:37:30 +0000 (13:37 +0000)
sqlite3_wal_checkpoint().  Other cleanup of WAL logic.

FossilOrigin-Name: 11a85b821abff1ecb7ec8c37bc7783be9fc4ea6d

manifest
manifest.uuid
src/main.c
src/pragma.c
src/sqliteInt.h

index 4bc4e4a91f1e8f3c00213bf3fe072c91e37d8399..8ce641e0deb33215c36c5f8be8e70f67d796172b 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,8 @@
-C Have\ssqlite3_wal_checkpoint()\spopulate\sthe\sdatabase\shandle\serror\smessage\sand\serror\scode\s(as\sreturned\sby\ssqlite3_errmsg()\sand\ssqlite3_errcode()).
-D 2010-05-03T12:14:16
+-----BEGIN PGP SIGNED MESSAGE-----
+Hash: SHA1
+
+C Make\ssure\sthe\smutex\sis\sheld\swhile\scalling\ssqlite3ApiExit()\sin\s\nsqlite3_wal_checkpoint().\s\sOther\scleanup\sof\sWAL\slogic.
+D 2010-05-03T13:37:30
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in d83a0ffef3dcbfb08b410a6c6dd6c009ec9167fb
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -131,7 +134,7 @@ F src/journal.c b0ea6b70b532961118ab70301c00a33089f9315c
 F src/legacy.c a199d7683d60cef73089e892409113e69c23a99f
 F src/lempar.c 7f026423f4d71d989e719a743f98a1cbd4e6d99e
 F src/loadext.c 1c7a61ce1281041f437333f366a96aa0d29bb581
-F src/main.c 1cc6f391018f2b868d812bf2b1be7c20a5269805
+F src/main.c 0f66a2b0c2ce2c44ab4a5436e05064d39d8f5cbf
 F src/malloc.c a08f16d134f0bfab6b20c3cd142ebf3e58235a6a
 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
 F src/mem1.c 89d4ea8d5cdd55635cbaa48ad53132af6294cbb2
@@ -158,7 +161,7 @@ F src/parse.y ace5c7a125d9f2a410e431ee3209034105045f7e
 F src/pcache.c ace8f6a5ecd4711cc66a1b23053be7109bd437cf
 F src/pcache.h c683390d50f856d4cd8e24342ae62027d1bb6050
 F src/pcache1.c 6dc1871ce8ead9187161c370a58cd06c84221f76
-F src/pragma.c 4540555271b98366a408289318c7c1e508d7c8a6
+F src/pragma.c 5fa66bc24bd4e842d3edb86a319223b86ba5493c
 F src/prepare.c fd1398cb1da54385ba5bd68d93928f10d10a1d9c
 F src/printf.c 5f5b65a83e63f2096a541a340722a509fa0240a7
 F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50
@@ -168,7 +171,7 @@ F src/select.c c03d8a0565febcde8c6a12c5d77d065fddae889b
 F src/shell.c c40427c7245535a04a9cb4a417b6cc05c022e6a4
 F src/sqlite.h.in 8097161ad63e2a00e26217da43327d396371c2e5
 F src/sqlite3ext.h 69dfb8116af51b84a029cddb3b35062354270c89
-F src/sqliteInt.h cb2b63a9538b9e79fc41b6d5026703600ab84407
+F src/sqliteInt.h e7f1368eb56d8a410e510bcffb9ca5795060c58c
 F src/sqliteLimit.h 196e2f83c3b444c4548fc1874f52f84fdbda40f3
 F src/status.c 4df6fe7dce2d256130b905847c6c60055882bdbe
 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
@@ -808,7 +811,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P 714e5947264571386f966aa8fcdd5607b5832238
-R 10b5fe590305e038296dabbf1b136051
-U dan
-Z 5bc5dc751e1eadc239ebcfefeac3d5fa
+P ff234cf574c7ae384ab1ebc79b2171ef0541bc91
+R e7545824307d5d5af98e4766ae2a26ad
+U drh
+Z 9a835b2804bf8190a366f2e988463519
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v1.4.6 (GNU/Linux)
+
+iD8DBQFL3tGdoxKgR168RlERAkuOAJ96ZgqU19yVJ4CAdOh6a78a7JzGjwCfSnph
+d7jKPMvbqcd69IRRUWbjMNM=
+=vT7t
+-----END PGP SIGNATURE-----
index 170e46abc9b7c122ab2e7f789f7c9887eedab509..a1b1094a48de4bdba252b3271824fd2764da8f3b 100644 (file)
@@ -1 +1 @@
-ff234cf574c7ae384ab1ebc79b2171ef0541bc91
\ No newline at end of file
+11a85b821abff1ecb7ec8c37bc7783be9fc4ea6d
\ No newline at end of file
index 2767878f8e773578cc66779ede3a0f5b22bccc61..bb0f17c25721a7e60544c552e5b43d025e100c43 100644 (file)
@@ -1191,13 +1191,19 @@ void *sqlite3_rollback_hook(
 ** The sqlite3_wal_hook() callback registered by sqlite3_wal_autocheckpoint().
 ** Return non-zero, indicating to the caller that a checkpoint should be run,
 ** if the number of frames in the log file is greater than 
-** sqlite3.nAutoCheckpoint (the value configured by wal_autocheckpoint()).
+** sqlite3.pWalArg cast to an integer (the value configured by
+** wal_autocheckpoint()).
 */ 
-static int defaultWalHook(void *p, sqlite3 *db, const char *z, int nFrame){
-  UNUSED_PARAMETER(p);
-  UNUSED_PARAMETER(z);
-  return ( nFrame>=db->nAutoCheckpoint );
+int sqlite3WalDefaultHook(
+  void *p,               /* Argument */
+  sqlite3 *db,           /* Connection */
+  const char *zNotUsed,  /* Database */
+  int nFrame             /* Size of WAL */
+){
+  UNUSED_PARAMETER(zNotUsed);
+  return ( nFrame>=SQLITE_PTR_TO_INT(p));
 }
+#endif /* SQLITE_OMIT_WAL */
 
 /*
 ** Configure an sqlite3_wal_hook() callback to automatically checkpoint
@@ -1211,14 +1217,15 @@ static int defaultWalHook(void *p, sqlite3 *db, const char *z, int nFrame){
 ** configured by this function.
 */
 int sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){
+#ifndef SQLITE_OMIT_WAL
   sqlite3_mutex_enter(db->mutex);
   if( nFrame>0 ){
-    sqlite3_wal_hook(db, defaultWalHook, 0);
-    db->nAutoCheckpoint = nFrame;
+    sqlite3_wal_hook(db, sqlite3WalDefaultHook, SQLITE_INT_TO_PTR(nFrame));
   }else{
     sqlite3_wal_hook(db, 0, 0);
   }
   sqlite3_mutex_leave(db->mutex);
+#endif
   return SQLITE_OK;
 }
 
@@ -1231,20 +1238,27 @@ void *sqlite3_wal_hook(
   int(*xCallback)(void *, sqlite3*, const char*, int),
   void *pArg                      /* First argument passed to xCallback() */
 ){
+#ifndef SQLITE_OMIT_WAL
   void *pRet;
   sqlite3_mutex_enter(db->mutex);
   pRet = db->pWalArg;
   db->xWalCallback = xCallback;
   db->pWalArg = pArg;
-  db->nAutoCheckpoint = 0;
   sqlite3_mutex_leave(db->mutex);
   return pRet;
+#else
+  return 0;
+#endif
 }
 
+
 /*
 ** Checkpoint database zDb. If zDb is NULL, the main database is checkpointed.
 */
 int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb){
+#ifdef SQLITE_OMIT_WAL
+  return SQLITE_OK;
+#else
   int rc;                         /* Return code */
   int iDb = 0;                    /* sqlite3.aDb[] index of db to checkpoint */
 
@@ -1259,11 +1273,13 @@ int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb){
     rc = sqlite3Checkpoint(db, iDb);
     sqlite3Error(db, rc, 0);
   }
+  rc = sqlite3ApiExit(db, rc);
   sqlite3_mutex_leave(db->mutex);
-
-  return sqlite3ApiExit(db, rc);
+  return rc;
+#endif
 }
 
+#ifndef SQLITE_OMIT_WAL
 /*
 ** Run a checkpoint on database iDb. This is a no-op if database iDb is
 ** not currently open in WAL mode.
@@ -1294,24 +1310,7 @@ int sqlite3Checkpoint(sqlite3 *db, int iDb){
 
   return rc;
 }
-#else /* ifndef SQLITE_OMIT_WAL */
-/*
-** If SQLITE_OMIT_WAL is defined, the following API functions are no-ops:
-**
-**   sqlite3_wal_hook()
-**   sqlite3_wal_checkpoint()
-**   sqlite3_wal_autocheckpoint()
-*/
-void *sqlite3_wal_hook(
-  sqlite3 *x,
-  int(*xCallback)(void *, sqlite3*, const char*, int),
-  void *pArg
-){
-  return 0;
-}
-int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb){ return SQLITE_OK; }
-int sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){ return SQLITE_OK; }
-#endif
+#endif /* SQLITE_OMIT_WAL */
 
 /*
 ** This function returns true if main-memory should be used instead of
index 0d2be03daf967fcd8b98efbc97e81e84735d9c1c..65a0550bcbe40d825b0b95bb39b2d862dfd32032 100644 (file)
@@ -1424,7 +1424,9 @@ void sqlite3Pragma(
       int nAuto = atoi(zRight);
       sqlite3_wal_autocheckpoint(db, nAuto);
     }
-    returnSingleInt(pParse, "wal_autocheckpoint", db->nAutoCheckpoint);
+    returnSingleInt(pParse, "wal_autocheckpoint", 
+       db->xWalCallback==sqlite3WalDefaultHook ? 
+           SQLITE_PTR_TO_INT(db->pWalArg) : 0);
   }else
 #endif
 
index c216816f6aa5e459ee131beb5aefccae03a8f782..842917a9b1b649f8283dbf334e29156ae8838123 100644 (file)
@@ -824,7 +824,6 @@ struct sqlite3 {
   void *pUpdateArg;
   void (*xUpdateCallback)(void*,int, const char*,const char*,sqlite_int64);
 #ifndef SQLITE_OMIT_WAL
-  int nAutoCheckpoint;          /* Value configured by wal_autocheckpoint() */
   int (*xWalCallback)(void *, sqlite3 *, const char *, int);
   void *pWalArg;
 #endif
@@ -3000,6 +2999,7 @@ int sqlite3TempInMemory(const sqlite3*);
 VTable *sqlite3GetVTable(sqlite3*, Table*);
 const char *sqlite3JournalModename(int);
 int sqlite3Checkpoint(sqlite3*, int);
+int sqlite3WalDefaultHook(void*,sqlite3*,const char*,int);
 
 /* Declarations for functions in fkey.c. All of these are replaced by
 ** no-op macros if OMIT_FOREIGN_KEY is defined. In this case no foreign