]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Optimizations to the OS sub-type checking in the Win32 VFS.
authormistachkin <mistachkin@noemail.net>
Thu, 31 Jul 2014 18:54:01 +0000 (18:54 +0000)
committermistachkin <mistachkin@noemail.net>
Thu, 31 Jul 2014 18:54:01 +0000 (18:54 +0000)
FossilOrigin-Name: 1e5489faff093d6a8e538061e45532f9050e9459

manifest
manifest.uuid
src/mutex_w32.c
src/os_win.c
src/test1.c

index 13634c500c7eedbbd812a3790f43be820b28ff28..498fa5f6582488fd4f817eb72cadf404145d457c 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\sa\smissing\scall\sto\s"test_sqlite3_log"\sto\smultiplex.test.
-D 2014-07-31T18:14:37.512
+C Optimizations\sto\sthe\sOS\ssub-type\schecking\sin\sthe\sWin32\sVFS.
+D 2014-07-31T18:54:01.916
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -201,14 +201,14 @@ F src/mutex.c 84a073c9a23a8d7bdd2ea832522d1730df18812c
 F src/mutex.h 5bc526e19dccc412b7ff04642f6fdad3fdfdabea
 F src/mutex_noop.c f3f09fd7a2eb4287cfc799753ffc30380e7b71a1
 F src/mutex_unix.c 1b10d5413dfc794364a8adf3eb3a192926b43fa3
-F src/mutex_w32.c 08890085b81ce181d2cbc6fc2636e3444ae30b27
+F src/mutex_w32.c c50939b72368f1cfbddb58520372081a50558548
 F src/notify.c 976dd0f6171d4588e89e874fcc765e92914b6d30
 F src/os.c 1b147e4cf7cc39e618115c14a086aed44bc91ace
 F src/os.h 60d419395e32a8029fa380a80a3da2e9030f635e
 F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04
 F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa
 F src/os_unix.c a7baf1b30f3c58ba20b813e01aab23b18ae44f85
-F src/os_win.c c29e3a80b47ebdbabd61fc3d4015e52d2654d8c5
+F src/os_win.c c67bec43e5dadde8029470ab7b7825ccc9abe578
 F src/os_win.h 057344a6720b4c8405d9bd98f58cb37a6ee46c25
 F src/pager.c f6bb1fa6cdf2062f2d8aec3e64db302bca519ab8
 F src/pager.h ffd5607f7b3e4590b415b007a4382f693334d428
@@ -232,7 +232,7 @@ F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
 F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158
 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
 F src/tclsqlite.c e87c99e28a145943666b51b212dacae35fcea0bd
-F src/test1.c 3c8bc491d2f8de5adbbf306533cefc343c733927
+F src/test1.c 14409a611e9c27c6c522c610bbff5561f05c1558
 F src/test2.c 98049e51a17dc62606a99a9eb95ee477f9996712
 F src/test3.c 1c0e5d6f080b8e33c1ce8b3078e7013fdbcd560c
 F src/test4.c 9b32d22f5f150abe23c1830e2057c4037c45b3df
@@ -1185,7 +1185,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 47457b0488abcbec2137abf706c1d677563b9ea5
-R 40079bb444b74388b9936aaa1a8a8059
-U dan
-Z a0b960eb92c17485651b9cbc9a7c3b70
+P 0708f9df23a325349f658741358c5994b5c4c873
+R 33905802a155aabab7e0415ce706b3b1
+U mistachkin
+Z f67dc40e0d7f1ad1a9a6019eb7b3fb85
index fa6a4ad3e8b37a7696c4060130a89e90e8ff523e..42ebb3917ee9c7faec0a5de6e36f938890296b31 100644 (file)
@@ -1 +1 @@
-0708f9df23a325349f658741358c5994b5c4c873
\ No newline at end of file
+1e5489faff093d6a8e538061e45532f9050e9459
\ No newline at end of file
index c34f28f0e42381c367049e79344ce1ba003b605d..218342d2b9cb474576102b996719b200919daf0e 100644 (file)
@@ -93,12 +93,13 @@ static sqlite3_mutex winMutex_staticMutexes[] = {
 };
 
 static int winMutex_isInit = 0;
+static int winMutex_isNt = -1; /* <0 means "need to query" */
 
 /* As the winMutexInit() and winMutexEnd() functions are called as part
 ** of the sqlite3_initialize() and sqlite3_shutdown() processing, the
 ** "interlocked" magic used here is probably not strictly necessary.
 */
-static LONG winMutex_lock = 0;
+static LONG volatile winMutex_lock = 0;
 
 int sqlite3_win32_is_nt(void); /* os_win.c */
 void sqlite3_win32_sleep(DWORD milliseconds); /* os_win.c */
@@ -295,7 +296,12 @@ static int winMutexTry(sqlite3_mutex *p){
   */
 #if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0400
   assert( winMutex_isInit==1 );
-  if( sqlite3_win32_is_nt() && TryEnterCriticalSection(&p->mutex) ){
+  assert( winMutex_isNt>=-1 && winMutex_isNt<=1 );
+  if( winMutex_isNt<0 ){
+    winMutex_isNt = sqlite3_win32_is_nt();
+  }
+  assert( winMutex_isNt==0 || winMutex_isNt==1 );
+  if( winMutex_isNt && TryEnterCriticalSection(&p->mutex) ){
 #ifdef SQLITE_DEBUG
     p->owner = tid;
     p->nRef++;
index 842a4ad7cf046526e91391fbe2ae85a43df6f1d1..fd2997206c4d2a96e84f883c307510e758908e48 100644 (file)
@@ -414,10 +414,10 @@ const sqlite3_mem_methods *sqlite3MemGetWin32(void);
 ** can manually set this value to 1 to emulate Win98 behavior.
 */
 #ifdef SQLITE_TEST
-int sqlite3_os_type = 0;
+LONG volatile sqlite3_os_type = 0;
 #elif !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && \
       defined(SQLITE_WIN32_HAS_ANSI) && defined(SQLITE_WIN32_HAS_WIDE)
-static int sqlite3_os_type = 0;
+static LONG volatile sqlite3_os_type = 0;
 #endif
 
 #ifndef SYSCALL
@@ -1048,6 +1048,11 @@ static struct win_syscall {
 #define osCreateFileMappingFromApp ((HANDLE(WINAPI*)(HANDLE, \
         LPSECURITY_ATTRIBUTES,ULONG,ULONG64,LPCWSTR))aSyscall[75].pCurrent)
 
+  { "InterlockedCompareExchange", (SYSCALL)InterlockedCompareExchange, 0 },
+
+#define osInterlockedCompareExchange ((LONG(WINAPI*)(LONG volatile*, \
+        LONG,LONG))aSyscall[76].pCurrent)
+
 }; /* End of the overrideable system calls */
 
 /*
@@ -1298,7 +1303,7 @@ void sqlite3_win32_sleep(DWORD milliseconds){
 #elif !defined(SQLITE_WIN32_HAS_WIDE)
 # define osIsNT()  (0)
 #else
-# define osIsNT()  (sqlite3_win32_is_nt())
+# define osIsNT()  ((sqlite3_os_type==2) || sqlite3_win32_is_nt())
 #endif
 
 /*
@@ -1306,7 +1311,7 @@ void sqlite3_win32_sleep(DWORD milliseconds){
 ** based on the NT kernel.
 */
 int sqlite3_win32_is_nt(void){
-  if( sqlite3_os_type==0 ){
+  if( osInterlockedCompareExchange(&sqlite3_os_type, 0, 0)==0 ){
 #if defined(NTDDI_VERSION) && NTDDI_VERSION >= NTDDI_WIN8
     OSVERSIONINFOW sInfo;
     sInfo.dwOSVersionInfoSize = sizeof(sInfo);
@@ -1316,9 +1321,10 @@ int sqlite3_win32_is_nt(void){
     sInfo.dwOSVersionInfoSize = sizeof(sInfo);
     osGetVersionExA(&sInfo);
 #endif
-    sqlite3_os_type = (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1;
+    osInterlockedCompareExchange(&sqlite3_os_type,
+        (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0);
   }
-  return (sqlite3_os_type == 2);
+  return osInterlockedCompareExchange(&sqlite3_os_type, 2, 2)==2;
 }
 
 #ifdef SQLITE_WIN32_MALLOC
@@ -5475,7 +5481,7 @@ int sqlite3_os_init(void){
 
   /* Double-check that the aSyscall[] array has been constructed
   ** correctly.  See ticket [bb3a86e890c8e96ab] */
-  assert( ArraySize(aSyscall)==76 );
+  assert( ArraySize(aSyscall)==77 );
 
   /* get memory map allocation granularity */
   memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
index 8d2249cbb8f9ae35bb1f2e9b86a4cc96bf5fbaca..56487f6abb30e6de722442d4fb3ec2998f96e997 100644 (file)
@@ -6581,7 +6581,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
   extern int sqlite3_pager_writedb_count;
   extern int sqlite3_pager_writej_count;
 #if SQLITE_OS_WIN
-  extern int sqlite3_os_type;
+  extern LONG volatile sqlite3_os_type;
 #endif
 #ifdef SQLITE_DEBUG
   extern int sqlite3WhereTrace;
@@ -6639,7 +6639,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
 #endif
 #if SQLITE_OS_WIN
   Tcl_LinkVar(interp, "sqlite_os_type",
-      (char*)&sqlite3_os_type, TCL_LINK_INT);
+      (char*)&sqlite3_os_type, TCL_LINK_LONG);
 #endif
 #ifdef SQLITE_TEST
   {