From: drh Date: Fri, 30 Mar 2012 15:57:45 +0000 (+0000) Subject: Simplify the winRead and winWrite VFS functions to reduce the number X-Git-Tag: mountain-lion~3^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f0146403a62fdabac7acca4b9d9ec58b99213efc;p=thirdparty%2Fsqlite.git Simplify the winRead and winWrite VFS functions to reduce the number of system calls. FossilOrigin-Name: b34491869c4fb31d2fdd14c94a7db2e1c0e572ba --- diff --git a/manifest b/manifest index 4181c0f6f2..47f54b8cc9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\sa\snamed\sCHECK\sconstraint\sfails,\sinclude\sthe\sname\sof\sthe\sconstraint\nin\sthe\serror\smessage. -D 2012-03-30T15:48:48.787 +C Simplify\sthe\swinRead\sand\swinWrite\sVFS\sfunctions\sto\sreduce\sthe\snumber\nof\ssystem\scalls. +D 2012-03-30T15:57:45.451 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 2f37e468503dbe79d35c9f6dffcf3fae1ae9ec20 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -168,7 +168,7 @@ F src/os.h 59beba555b65a450bd1d804220532971d4299f60 F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_os2.c 4a75888ba3dfc820ad5e8177025972d74d7f2440 F src/os_unix.c 0e3d2942d228d0366fb80a3640f35caf413b66d1 -F src/os_win.c 5ac061ae1326a71500cee578ed0fd9113b4f6a37 +F src/os_win.c c7b26b78c5e62de7355ad79e0ce79d7b0f5fccc4 F src/pager.c 85988507fa20acc60defb834722eddf4633e4aeb F src/pager.h ef1eaf8593e78f73885c1dfac27ad83bee23bdc5 F src/parse.y eb054bb40a5bf90d3422a01ed0e5df229461727a @@ -999,7 +999,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 -P cb7a850439c9a4a7887650d6b81d95ab8025de5b 9a0f90d9deb335ac71044b8afa81538d85cc7ccf -R 3383713cde4154ba8c7927e87d965912 +P 1b75f301affac654bee24fa247046ea0782d3c4d +R 2cc6bffd476fbc89b05bef18789bd072 U drh -Z 044e1c348f17a4e06833c51581164485 +Z 6ac97e4f60396b50617248087122bd36 diff --git a/manifest.uuid b/manifest.uuid index a240625a11..8107006afc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1b75f301affac654bee24fa247046ea0782d3c4d \ No newline at end of file +b34491869c4fb31d2fdd14c94a7db2e1c0e572ba \ No newline at end of file diff --git a/src/os_win.c b/src/os_win.c index 8b86c7ed59..5826be688f 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -1616,6 +1616,9 @@ static int winClose(sqlite3_file *id){ } #endif OSTRACE(("CLOSE %d %s\n", pFile->h, rc ? "ok" : "failed")); + if( rc ){ + pFile->h = NULL; + } OpenCounter(-1); return rc ? SQLITE_OK : winLogError(SQLITE_IOERR_CLOSE, osGetLastError(), @@ -1633,6 +1636,7 @@ static int winRead( int amt, /* Number of bytes to read */ sqlite3_int64 offset /* Begin reading at this offset */ ){ + OVERLAPPED overlapped; /* The offset for ReadFile. */ winFile *pFile = (winFile*)id; /* file handle */ DWORD nRead; /* Number of bytes actually read from file */ int nRetry = 0; /* Number of retrys */ @@ -1641,10 +1645,11 @@ static int winRead( SimulateIOError(return SQLITE_IOERR_READ); OSTRACE(("READ %d lock=%d\n", pFile->h, pFile->locktype)); - if( seekWinFile(pFile, offset) ){ - return SQLITE_FULL; - } - while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){ + memset(&overlapped, 0, sizeof(OVERLAPPED)); + overlapped.Offset = (LONG)(offset & 0xffffffff); + overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff); + while( !osReadFile(pFile->h, pBuf, amt, &nRead, &overlapped) && + osGetLastError()!=ERROR_HANDLE_EOF ){ DWORD lastErrno; if( retryIoerr(&nRetry, &lastErrno) ) continue; pFile->lastErrno = lastErrno; @@ -1671,7 +1676,7 @@ static int winWrite( int amt, /* Number of bytes to write */ sqlite3_int64 offset /* Offset into the file to begin writing at */ ){ - int rc; /* True if error has occured, else false */ + int rc = 0; /* True if error has occured, else false */ winFile *pFile = (winFile*)id; /* File handle */ int nRetry = 0; /* Number of retries */ @@ -1682,19 +1687,29 @@ static int winWrite( OSTRACE(("WRITE %d lock=%d\n", pFile->h, pFile->locktype)); - rc = seekWinFile(pFile, offset); - if( rc==0 ){ + { + OVERLAPPED overlapped; /* The offset for WriteFile. */ u8 *aRem = (u8 *)pBuf; /* Data yet to be written */ int nRem = amt; /* Number of bytes yet to be written */ DWORD nWrite; /* Bytes written by each WriteFile() call */ DWORD lastErrno = NO_ERROR; /* Value returned by GetLastError() */ + memset(&overlapped, 0, sizeof(OVERLAPPED)); + overlapped.Offset = (LONG)(offset & 0xffffffff); + overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff); + while( nRem>0 ){ - if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){ + if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, &overlapped) ){ if( retryIoerr(&nRetry, &lastErrno) ) continue; break; } - if( nWrite<=0 ) break; + if( nWrite<=0 ){ + lastErrno = osGetLastError(); + break; + } + offset += nWrite; + overlapped.Offset = (LONG)(offset & 0xffffffff); + overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff); aRem += nWrite; nRem -= nWrite; }