]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Enhance the Windows VFS to recognize SQLITE_FCNTL_LOCK_TIMEOUT and make
authordrh <>
Wed, 14 Jul 2021 19:35:45 +0000 (19:35 +0000)
committerdrh <>
Wed, 14 Jul 2021 19:35:45 +0000 (19:35 +0000)
the value set there available to the winLockFile() function.

FossilOrigin-Name: 954b5d61299d82312a9ca2764f904e2d8318c469f6749d84f8a6871d12a575a8

manifest
manifest.uuid
src/os_win.c

index 218b1abbf1dbe9056f297a3a53c0a7683ee5d5a6..e552a4aba7b8a0f206da4c038bf3aeeb4dcecf4d 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Enhance\scomments\spertaining\sto\sthe\sinterface\slinkage\s/\scalling\sconvention\smacros.
-D 2021-07-13T22:49:02.204
+C Enhance\sthe\sWindows\sVFS\sto\srecognize\sSQLITE_FCNTL_LOCK_TIMEOUT\sand\smake\nthe\svalue\sset\sthere\savailable\sto\sthe\swinLockFile()\sfunction.
+D 2021-07-14T19:35:45.291
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -529,7 +529,7 @@ F src/os.h 26890f540b475598cd9881dcc68931377b8d429d3ea3e2eeb64470cde64199f8
 F src/os_common.h b2f4707a603e36811d9b1a13278bffd757857b85
 F src/os_setup.h 0dbaea40a7d36bf311613d31342e0b99e2536586
 F src/os_unix.c b11e4610769922253dec27d7af4a07ff84f65169d19bda5e9b12a152a706f7f5
-F src/os_win.c 77d39873836f1831a9b0b91894fec45ab0e9ca8e067dc8c549e1d1eca1566fe9
+F src/os_win.c dc54e0a4b15a0c151dc9f01e64976d8f435d8020f0a8507d7acc5452b438d229
 F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a
 F src/pager.c 95c255256b13827caf038c8f963d334784073f38ab6ef9d70371d9d04f3c43e0
 F src/pager.h 4bf9b3213a4b2bebbced5eaa8b219cf25d4a82f385d093cd64b7e93e5285f66f
@@ -1920,7 +1920,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 9a84321229ad499ee0f7c85732c2728afb4476c72073a510401a559dda9be38f
-R 3789b43d6e6200974e3100b41a3c444f
-U mistachkin
-Z eb61d76fb75de1f468d1b3d6692793bb
+P c378e99250fe06fae8ca40c62185b607f004d6806e07dbb9f964dd849b4e55f8
+R 21f9449dd33d80268629340267e31b8d
+T *branch * win-blocking-locks
+T *sym-win-blocking-locks *
+T -sym-trunk *
+U drh
+Z 229f4697970d0911e5dbcc6bd7ebdd8d
index f6b958ea4097d23d6d7afab58592fe5669750024..bfa8f19f1ec9c95a82d65721d02f30f5fcb2ca3f 100644 (file)
@@ -1 +1 @@
-c378e99250fe06fae8ca40c62185b607f004d6806e07dbb9f964dd849b4e55f8
\ No newline at end of file
+954b5d61299d82312a9ca2764f904e2d8318c469f6749d84f8a6871d12a575a8
\ No newline at end of file
index d7c436eff91ff675f7cf9adad8b6ac82926baace..059e884ee3f21dc6c07be5a188313d35225f89fe 100644 (file)
@@ -272,6 +272,7 @@ struct winFile {
   winShm *pShm;           /* Instance of shared memory on this file */
 #endif
   const char *zPath;      /* Full pathname of this file */
+  unsigned iBusyTimeout;  /* Wait this many millisec on locks */
   int szChunk;            /* Chunk size configured by FCNTL_CHUNK_SIZE */
 #if SQLITE_OS_WINCE
   LPWSTR zDeleteOnClose;  /* Name of file to delete when closing */
@@ -2503,9 +2504,13 @@ static BOOL winceUnlockFile(
 
 /*
 ** Lock a file region.
+**
+** If the pFile->iBusyTimeout value is non-zero and the lock cannot be
+** acquired immediately, then try to block for up to iBusyTimeout milliseconds
+** waiting on the conflicting lock to appear.
 */
 static BOOL winLockFile(
-  LPHANDLE phFile,
+  winFile *pFile,
   DWORD flags,
   DWORD offsetLow,
   DWORD offsetHigh,
@@ -2517,7 +2522,7 @@ static BOOL winLockFile(
   ** NOTE: Windows CE is handled differently here due its lack of the Win32
   **       API LockFile.
   */
-  return winceLockFile(phFile, offsetLow, offsetHigh,
+  return winceLockFile(&pFile->h, offsetLow, offsetHigh,
                        numBytesLow, numBytesHigh);
 #else
   if( osIsNT() ){
@@ -2525,9 +2530,9 @@ static BOOL winLockFile(
     memset(&ovlp, 0, sizeof(OVERLAPPED));
     ovlp.Offset = offsetLow;
     ovlp.OffsetHigh = offsetHigh;
-    return osLockFileEx(*phFile, flags, 0, numBytesLow, numBytesHigh, &ovlp);
+    return osLockFileEx(pFile->h, flags, 0, numBytesLow, numBytesHigh, &ovlp);
   }else{
-    return osLockFile(*phFile, offsetLow, offsetHigh, numBytesLow,
+    return osLockFile(pFile->h, offsetLow, offsetHigh, numBytesLow,
                       numBytesHigh);
   }
 #endif
@@ -3162,7 +3167,7 @@ static int winGetReadLock(winFile *pFile){
     */
     res = winceLockFile(&pFile->h, SHARED_FIRST, 0, 1, 0);
 #else
-    res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS, SHARED_FIRST, 0,
+    res = winLockFile(pFile, SQLITE_LOCKFILEEX_FLAGS, SHARED_FIRST, 0,
                       SHARED_SIZE, 0);
 #endif
   }
@@ -3171,7 +3176,7 @@ static int winGetReadLock(winFile *pFile){
     int lk;
     sqlite3_randomness(sizeof(lk), &lk);
     pFile->sharedLockByte = (short)((lk & 0x7fffffff)%(SHARED_SIZE - 1));
-    res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS,
+    res = winLockFile(pFile, SQLITE_LOCKFILE_FLAGS,
                       SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
   }
 #endif
@@ -3275,7 +3280,7 @@ static int winLock(sqlite3_file *id, int locktype){
    || (locktype==EXCLUSIVE_LOCK && pFile->locktype<=RESERVED_LOCK)
   ){
     int cnt = 3;
-    while( cnt-->0 && (res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS,
+    while( cnt-->0 && (res = winLockFile(pFile, SQLITE_LOCKFILE_FLAGS,
                                          PENDING_BYTE, 0, 1, 0))==0 ){
       /* Try 3 times to get the pending lock.  This is needed to work
       ** around problems caused by indexing and/or anti-virus software on
@@ -3317,7 +3322,7 @@ static int winLock(sqlite3_file *id, int locktype){
   */
   if( locktype==RESERVED_LOCK && res ){
     assert( pFile->locktype==SHARED_LOCK );
-    res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, RESERVED_BYTE, 0, 1, 0);
+    res = winLockFile(pFile, SQLITE_LOCKFILE_FLAGS, RESERVED_BYTE, 0, 1, 0);
     if( res ){
       newLocktype = RESERVED_LOCK;
     }else{
@@ -3337,7 +3342,7 @@ static int winLock(sqlite3_file *id, int locktype){
   if( locktype==EXCLUSIVE_LOCK && res ){
     assert( pFile->locktype>=SHARED_LOCK );
     res = winUnlockReadLock(pFile);
-    res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, SHARED_FIRST, 0,
+    res = winLockFile(pFile, SQLITE_LOCKFILE_FLAGS, SHARED_FIRST, 0,
                       SHARED_SIZE, 0);
     if( res ){
       newLocktype = EXCLUSIVE_LOCK;
@@ -3388,7 +3393,7 @@ static int winCheckReservedLock(sqlite3_file *id, int *pResOut){
     res = 1;
     OSTRACE(("TEST-WR-LOCK file=%p, result=%d (local)\n", pFile->h, res));
   }else{
-    res = winLockFile(&pFile->h, SQLITE_LOCKFILEEX_FLAGS,RESERVED_BYTE,0,1,0);
+    res = winLockFile(pFile, SQLITE_LOCKFILEEX_FLAGS,RESERVED_BYTE,0,1,0);
     if( res ){
       winUnlockFile(&pFile->h, RESERVED_BYTE, 0, 1, 0);
     }
@@ -3527,6 +3532,12 @@ static int winFileControl(sqlite3_file *id, int op, void *pArg){
       OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
       return SQLITE_OK;
     }
+    case SQLITE_FCNTL_LOCK_TIMEOUT: {
+      int iOld = pFile->iBusyTimeout;
+      pFile->iBusyTimeout = *(int*)pArg;
+      *(int*)pArg = iOld;
+      return SQLITE_OK;
+    }
     case SQLITE_FCNTL_SIZE_HINT: {
       if( pFile->szChunk>0 ){
         sqlite3_int64 oldSz;
@@ -3804,7 +3815,7 @@ static int winShmSystemLock(
     /* Initialize the locking parameters */
     DWORD dwFlags = LOCKFILE_FAIL_IMMEDIATELY;
     if( lockType == WINSHM_WRLCK ) dwFlags |= LOCKFILE_EXCLUSIVE_LOCK;
-    rc = winLockFile(&pFile->hFile.h, dwFlags, ofst, 0, nByte, 0);
+    rc = winLockFile(&pFile->hFile, dwFlags, ofst, 0, nByte, 0);
   }
 
   if( rc!= 0 ){
@@ -4085,6 +4096,7 @@ static int winShmLock(
   mask = (u16)((1U<<(ofst+n)) - (1U<<ofst));
   assert( n>1 || mask==(1<<ofst) );
   sqlite3_mutex_enter(pShmNode->mutex);
+  pShmNode->hFile.iBusyTimeout = pDbFd->iBusyTimeout;
   if( flags & SQLITE_SHM_UNLOCK ){
     u16 allMask = 0; /* Mask of locks held by siblings */