diff options
author | dan <Dan Kennedy> | 2024-11-25 16:54:10 +0000 |
---|---|---|
committer | dan <Dan Kennedy> | 2024-11-25 16:54:10 +0000 |
commit | 1743c5f8369a58b90d212be840b12d88c658f47c (patch) | |
tree | 0844017f8d7fd29996118a97565945e7a6e4c3d7 | |
parent | 6bd3faa09248a8ec70e706041afeac42610f443b (diff) | |
download | sqlite-1743c5f8369a58b90d212be840b12d88c658f47c.tar.gz sqlite-1743c5f8369a58b90d212be840b12d88c658f47c.zip |
Fixes for code on this branch. Now appears to work, but is not tested well.
FossilOrigin-Name: 0568fc6dde41dd29e85e697cd1865feb4db6aaae09d5e5100b3f97cab93590eb
-rw-r--r-- | manifest | 15 | ||||
-rw-r--r-- | manifest.uuid | 2 | ||||
-rw-r--r-- | src/os_win.c | 50 |
3 files changed, 42 insertions, 25 deletions
@@ -1,5 +1,5 @@ -C Supports\sSQLITE_ENABLE_SETLK_TIMEOUT\son\swindows.\sDoes\snot\swork\sproperly\syet. -D 2024-11-22T21:24:08.721 +C Fixes\sfor\scode\son\sthis\sbranch.\sNow\sappears\sto\swork,\sbut\sis\snot\stested\swell. +D 2024-11-25T16:54:10.680 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md e108e1e69ae8e8a59e93c455654b8ac9356a11720d3345df2a4743e9590fb20d @@ -759,7 +759,7 @@ F src/os_common.h 6c0eb8dd40ef3e12fe585a13e709710267a258e2c8dd1c40b1948a1d14582e F src/os_kv.c 4d39e1f1c180b11162c6dc4aa8ad34053873a639bac6baae23272fc03349986a F src/os_setup.h 6011ad7af5db4e05155f385eb3a9b4470688de6f65d6166b8956e58a3d872107 F src/os_unix.c d4a33e8fbd1c6eb722a21b6ce1eee1213ec856170a2f256d99f3d2978f054f5a -F src/os_win.c 2ed170fb6dba67952b7f07dfee71bb854463fb2fb51b0289fce5dec0fd075b0f +F src/os_win.c 89ba97de6b7b022a4955cc63cc75535ed8d792be8e68455c753996ebef7ec9ba F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c 9656ad4e8331efb8a4f94f7a0c6440b98caea073950a367ea0c728a53b8e62c9 F src/pager.h 4b1140d691860de0be1347474c51fee07d5420bd7f802d38cbab8ea4ab9f538a @@ -2199,11 +2199,8 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7 F tool/warnings.sh 49a486c5069de041aedcbde4de178293e0463ae9918ecad7539eedf0ec77a139 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 0fe1622cec95b7ebecc127ee57a08113d3da1dadbe72c03a13d6751b3043e50f -R ee8b39ab71f10eb6a0db7f5e0c48bbd2 -T *branch * win32-enable-setlk -T *sym-win32-enable-setlk * -T -sym-trunk * +P 737ca8a9fb9dc74b28f2186d93c5101463497445d0fabba3def61fee29abf2c8 +R 67627b8a16f9542753e5ce4ea1a59b13 U dan -Z e8f9e025559e2dfd331c377d699a5f1c +Z aaacd08c676a64c2d5781697fad0f96f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 3a08657fe..c9c2983ca 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -737ca8a9fb9dc74b28f2186d93c5101463497445d0fabba3def61fee29abf2c8 +0568fc6dde41dd29e85e697cd1865feb4db6aaae09d5e5100b3f97cab93590eb diff --git a/src/os_win.c b/src/os_win.c index ff094e8d1..be13d8348 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -16,6 +16,11 @@ #if SQLITE_OS_WIN /* This file is used for Windows only */ /* +** TODO: This must not clash with any other SQLITE_OPEN_XXX flag in sqlite3.h. +*/ +#define WIN32_OPEN_SHM 0x80000000 + +/* ** Include code that is common to all os_*.c files */ #include "os_common.h" @@ -2559,7 +2564,7 @@ static BOOL winLockFile( ** SQLITE_BUSY_TIMEOUT otherwise. Or, if an error occurs, SQLITE_IOERR. */ static int winLockFileTimeout( - LPHANDLE phFile, + HANDLE hFile, sqlite3_mutex *pMutex, DWORD offset, DWORD nByte, @@ -2571,37 +2576,43 @@ static int winLockFileTimeout( BOOL ret; #if !defined(SQLITE_ENABLE_SETLK_TIMEOUT) - ret = winLockFile(phFile, flags, offset, 0, nByte, 0); + ret = winLockFile(&hFile, flags, offset, 0, nByte, 0); #else if( !osIsNT() ){ - ret = winLockFile(phFile, flags, offset, 0, nByte, 0); + ret = winLockFile(&hFile, flags, offset, 0, nByte, 0); }else{ OVERLAPPED ovlp; memset(&ovlp, 0, sizeof(OVERLAPPED)); ovlp.Offset = offset; + if( nMs>0 ){ ovlp.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); if( ovlp.hEvent==NULL ){ return SQLITE_IOERR; } + flags &= ~LOCKFILE_FAIL_IMMEDIATELY; } - ret = osLockFileEx(*phFile, flags, 0, nByte, 0, &ovlp); - - if( nMs>0 ){ - if( !ret ){ - DWORD res = WaitForSingleObject(ovlp.hEvent, (DWORD)nMs); - if( res==WAIT_OBJECT_0 ){ - /* Successfully obtained the lock. */ - ret = TRUE; - }else if( res==WAIT_TIMEOUT ){ - /* Timeout */ + ret = osLockFileEx(hFile, flags, 0, nByte, 0, &ovlp); + if( !ret && nMs>0 && GetLastError()==ERROR_IO_PENDING ){ + DWORD res = WaitForSingleObject(ovlp.hEvent, (DWORD)nMs); + if( res==WAIT_OBJECT_0 ){ + /* Successfully obtained the lock. */ + ret = TRUE; + }else{ + if( res==WAIT_TIMEOUT ){ rc = SQLITE_BUSY_TIMEOUT; }else{ /* Some other error has occurred */ rc = SQLITE_IOERR; } + + /* Cancel the LockFileEx() if it is still pending. */ + CancelIo(hFile); } + } + + if( nMs>0 ){ CloseHandle(ovlp.hEvent); } } @@ -3954,7 +3965,7 @@ static int winShmSystemLock( }else{ /* Initialize the locking parameters */ #if SQLITE_ENABLE_SETLK_TIMEOUT - rc = winLockFileTimeout(&pShmNode->hFile.h, pShmNode->mutex, ofst, nByte, + rc = winLockFileTimeout(pShmNode->hFile.h, pShmNode->mutex, ofst, nByte, (lockType==WINSHM_WRLCK), pDbFd->iBusyTimeout); #else DWORD dwFlags = LOCKFILE_FAIL_IMMEDIATELY; @@ -4110,7 +4121,7 @@ static int winOpenSharedMemory(winFile *pDbFd){ if( pShmNode ){ sqlite3_free(pNew); }else{ - int inFlags = SQLITE_OPEN_WAL; + int inFlags = SQLITE_OPEN_WAL | WIN32_OPEN_SHM; int outFlags = 0; pShmNode = pNew; @@ -5443,6 +5454,15 @@ static int winOpen( dwFlagsAndAttributes |= FILE_FLAG_RANDOM_ACCESS; #endif + /* If we are really opening a *-shm file, and ENABLE_SETLK is defined, + ** open the file for overlapped-IO. This is to facilitate blocking locks + ** with timeouts, which use asynchronous IO on windows. */ +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT + if( flags & WIN32_OPEN_SHM ){ + dwFlagsAndAttributes |= FILE_FLAG_OVERLAPPED; + } +#endif + if( osIsNT() ){ #if SQLITE_OS_WINRT CREATEFILE2_EXTENDED_PARAMETERS extendedParameters; |