]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Define an invariant to guarantee deadlock-free operation of SHM in os_unix.c
authordrh <drh@noemail.net>
Sat, 1 May 2010 17:57:36 +0000 (17:57 +0000)
committerdrh <drh@noemail.net>
Sat, 1 May 2010 17:57:36 +0000 (17:57 +0000)
and check that invariant with assert() statements.

FossilOrigin-Name: 6af2dca75b8139134ea394c1d71aefc6523f02e9

manifest
manifest.uuid
src/os_unix.c

index 75db7fed56890b8e44820050868382a623a62d55..5a53af92b170177ba798434d2213191d9dd9de43 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,8 +1,8 @@
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
-C Rework\smutexes\son\sthe\sSHM\simplemention\sfor\sos_unix\sto\savoid\sa\sdeadlock\sduring\nWAL\srecovery.
-D 2010-05-01T17:50:38
+C Define\san\sinvariant\sto\sguarantee\sdeadlock-free\soperation\sof\sSHM\sin\sos_unix.c\nand\scheck\sthat\sinvariant\swith\sassert()\sstatements.
+D 2010-05-01T17:57:36
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in d83a0ffef3dcbfb08b410a6c6dd6c009ec9167fb
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -153,7 +153,7 @@ F src/os.c 8bc63cf91e9802e2b807198e54e50227fa889306
 F src/os.h 534b082c3cb349ad05fa6fa0b06087e022af282c
 F src/os_common.h 0d6ee583b6ee3185eb9d951f890c6dd03021a08d
 F src/os_os2.c 8ad77a418630d7dee91d1bb04f79c2096301d3a0
-F src/os_unix.c d402146bd3731575ff399d2ebcdc0867034e8451
+F src/os_unix.c bb8b65d92a79b4b1311fad7cae8a697dea0b8838
 F src/os_win.c a8fc01d8483be472e495793c01064fd87e56a5c1
 F src/pager.c e9c7fe979b32a3c5bf4216d8fbe1cf8beff8a1b8
 F src/pager.h 934b598583a9d936bb13c37d62a2fe68ac48781c
@@ -811,14 +811,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P 9b230c43dfa112e3e1589f9775926807bd36b36e
-R 70dfb91700ac677788e5556f2fcdd9f6
+P 1a0f69bef2c489e81a3d4b910b426972e9ed4054
+R 9a63fdaeb48f811dfa07166dc0124f9e
 U drh
-Z aec6f98e0ebcce7f7132104408636399
+Z 0ec029f9a2c3c35cece8a5840fe4c2a0
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.6 (GNU/Linux)
 
-iD8DBQFL3GnyoxKgR168RlERAm3bAJwJDWmdlrwEHnjKELzYU8/fifSwAQCeNiz2
-E59QAYMayqNW9OBp4QF0LdQ=
-=o6hV
+iD8DBQFL3GuToxKgR168RlERAruJAJ93UG+yjpg4IAjppTK82HawrL2+6ACfZrj+
+F2hwX359XH9Tj7T1X7t3awQ=
+=0PFi
 -----END PGP SIGNATURE-----
index c88f378a4b0fafd288e3e3157bb887952adad109..1b197ea0b1bcbe5c6cc492ee62dda373810cab37 100644 (file)
@@ -1 +1 @@
-1a0f69bef2c489e81a3d4b910b426972e9ed4054
\ No newline at end of file
+6af2dca75b8139134ea394c1d71aefc6523f02e9
\ No newline at end of file
index caf22effe6ace5194f4509d6e2c46f1ec5a0b5b1..e15d9d41664a5826660aea85627e439eb857cdb9 100644 (file)
@@ -4589,6 +4589,12 @@ typedef struct unixShmFile unixShmFile;
 ** Either unixShmFile.mutex must be held or unixShmFile.nRef==0 and
 ** unixMutexHeld() is true when reading or writing any other field
 ** in this structure.
+**
+** To avoid deadlocks, mutex and mutexBuf are always released in the
+** reverse order that they are acquired.  mutexBuf is always acquired
+** first and released last.  This invariant is check by asserting
+** sqlite3_mutex_notheld() on mutex whenever mutexBuf is acquired or
+** released.
 */
 struct unixShmFile {
   struct unixFileId fid;     /* Unique file identifier */
@@ -5146,6 +5152,7 @@ static int unixShmGet(
   int rc = SQLITE_OK;
 
   if( p->lockState!=SQLITE_SHM_CHECKPOINT && p->hasMutexBuf==0 ){
+    assert( sqlite3_mutex_notheld(pFile->mutex) );
     sqlite3_mutex_enter(pFile->mutexBuf);
     p->hasMutexBuf = 1;
   }
@@ -5184,6 +5191,7 @@ static int unixShmRelease(sqlite3_shm *pSharedMem){
   unixShm *p = (unixShm*)pSharedMem;
   if( p->hasMutexBuf && p->lockState!=SQLITE_SHM_RECOVER ){
     unixShmFile *pFile = p->pFile;
+    assert( sqlite3_mutex_notheld(pFile->mutex) );
     sqlite3_mutex_leave(pFile->mutexBuf);
     p->hasMutexBuf = 0;
   }
@@ -5246,6 +5254,7 @@ static int unixShmLock(
             p->id, getpid(), azLkName[p->lockState], azLkName[desiredLock]));
   
   if( desiredLock==SQLITE_SHM_RECOVER && !p->hasMutexBuf ){
+    assert( sqlite3_mutex_notheld(pFile->mutex) );
     sqlite3_mutex_enter(pFile->mutexBuf);
     p->hasMutexBuf = 1;
   }