]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Simplify the winRead and winWrite VFS functions to reduce the number of system calls.
authormistachkin <mistachkin@noemail.net>
Fri, 30 Mar 2012 12:27:55 +0000 (12:27 +0000)
committermistachkin <mistachkin@noemail.net>
Fri, 30 Mar 2012 12:27:55 +0000 (12:27 +0000)
FossilOrigin-Name: 10ce846759f6f22e70bb9b67bea7a0c2b8a156fe

manifest
manifest.uuid
src/os_win.c

index 9e1571b430f334841de02b2a4c4afbb1273d42e6..5d5fe7e76129433156764db08f628c68b150aa47 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Update\sMSVC\smakefile\sto\ssupport\scompiling\sfor\sWinRT\susing\sone\ssetting.
-D 2012-03-23T12:28:21.645
+C Simplify\sthe\swinRead\sand\swinWrite\sVFS\sfunctions\sto\sreduce\sthe\snumber\sof\ssystem\scalls.
+D 2012-03-30T12:27:55.620
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 2f37e468503dbe79d35c9f6dffcf3fae1ae9ec20
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -167,7 +167,7 @@ F src/os.h 38aabd5e3ecd4162332076f55bb09cec02165cca
 F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04
 F src/os_os2.c 4a75888ba3dfc820ad5e8177025972d74d7f2440
 F src/os_unix.c 0e3d2942d228d0366fb80a3640f35caf413b66d1
-F src/os_win.c d96547173049f48b6727972fd34b9fd9613d28e5
+F src/os_win.c 6f8080e783082d3d94ea56537f2248df4e273843
 F src/pager.c 3955b62cdb5bb64559607cb474dd12a6c8e1d4a5
 F src/pager.h ef1eaf8593e78f73885c1dfac27ad83bee23bdc5
 F src/parse.y 1ddd71ae55f4b7cbb2672526ea4de023de0f519e
@@ -992,7 +992,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
 F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a
 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
-P ddea657bd8fe3762bd460524ac9223f0a5b09752
-R 73aeb52e562bd72810737fc034c57c72
+P c10794bfac0989c611ec3ea98d069cb9631a7b15
+R 23bdb0c42f14336dabd08b128245de8d
 U mistachkin
-Z de85e312d806eace4ad69be21292db54
+Z 736498e20bf38fd876d04def8440845b
index 1b10195f13726ed1b8367ca32d3fa944c6e599dc..2a88abb7683d9ad8f08da7e445c1c949d922bc70 100644 (file)
@@ -1 +1 @@
-c10794bfac0989c611ec3ea98d069cb9631a7b15
\ No newline at end of file
+10ce846759f6f22e70bb9b67bea7a0c2b8a156fe
\ No newline at end of file
index db2ec09c1fb700cd828fa91d125318cab25a56e8..45fae46daa5255201cdecfb27d907c32829b454a 100644 (file)
@@ -1958,6 +1958,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(),
@@ -1975,6 +1978,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 */
@@ -1983,10 +1987,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;
@@ -2013,7 +2018,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 */
 
@@ -2024,19 +2029,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;
     }