/ Check-in [1e5489fa]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Optimizations to the OS sub-type checking in the Win32 VFS.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 1e5489faff093d6a8e538061e45532f9050e9459
User & Date: mistachkin 2014-07-31 18:54:01
Context
2014-07-31
20:16
Omit a pointless OP_Null when processing a value-list RHS of an IN operator where the LHS is a rowid. check-in: 1361450a user: drh tags: trunk
18:54
Optimizations to the OS sub-type checking in the Win32 VFS. check-in: 1e5489fa user: mistachkin tags: trunk
18:14
Add a missing call to "test_sqlite3_log" to multiplex.test. check-in: 0708f9df user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/mutex_w32.c.

    89     89     SQLITE3_MUTEX_INITIALIZER,
    90     90     SQLITE3_MUTEX_INITIALIZER,
    91     91     SQLITE3_MUTEX_INITIALIZER,
    92     92     SQLITE3_MUTEX_INITIALIZER
    93     93   };
    94     94   
    95     95   static int winMutex_isInit = 0;
           96  +static int winMutex_isNt = -1; /* <0 means "need to query" */
    96     97   
    97     98   /* As the winMutexInit() and winMutexEnd() functions are called as part
    98     99   ** of the sqlite3_initialize() and sqlite3_shutdown() processing, the
    99    100   ** "interlocked" magic used here is probably not strictly necessary.
   100    101   */
   101         -static LONG winMutex_lock = 0;
          102  +static LONG volatile winMutex_lock = 0;
   102    103   
   103    104   int sqlite3_win32_is_nt(void); /* os_win.c */
   104    105   void sqlite3_win32_sleep(DWORD milliseconds); /* os_win.c */
   105    106   
   106    107   static int winMutexInit(void){
   107    108     /* The first to increment to 1 does actual initialization */
   108    109     if( InterlockedCompareExchange(&winMutex_lock, 1, 0)==0 ){
................................................................................
   291    292     ** And some windows compilers complain if you try to use it without
   292    293     ** first doing some #defines that prevent SQLite from building on Win98.
   293    294     ** For that reason, we will omit this optimization for now.  See
   294    295     ** ticket #2685.
   295    296     */
   296    297   #if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0400
   297    298     assert( winMutex_isInit==1 );
   298         -  if( sqlite3_win32_is_nt() && TryEnterCriticalSection(&p->mutex) ){
          299  +  assert( winMutex_isNt>=-1 && winMutex_isNt<=1 );
          300  +  if( winMutex_isNt<0 ){
          301  +    winMutex_isNt = sqlite3_win32_is_nt();
          302  +  }
          303  +  assert( winMutex_isNt==0 || winMutex_isNt==1 );
          304  +  if( winMutex_isNt && TryEnterCriticalSection(&p->mutex) ){
   299    305   #ifdef SQLITE_DEBUG
   300    306       p->owner = tid;
   301    307       p->nRef++;
   302    308   #endif
   303    309       rc = SQLITE_OK;
   304    310     }
   305    311   #else

Changes to src/os_win.c.

   410    410   ** 1:   Operating system is Win9x.
   411    411   ** 2:   Operating system is WinNT.
   412    412   **
   413    413   ** In order to facilitate testing on a WinNT system, the test fixture
   414    414   ** can manually set this value to 1 to emulate Win98 behavior.
   415    415   */
   416    416   #ifdef SQLITE_TEST
   417         -int sqlite3_os_type = 0;
          417  +LONG volatile sqlite3_os_type = 0;
   418    418   #elif !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && \
   419    419         defined(SQLITE_WIN32_HAS_ANSI) && defined(SQLITE_WIN32_HAS_WIDE)
   420         -static int sqlite3_os_type = 0;
          420  +static LONG volatile sqlite3_os_type = 0;
   421    421   #endif
   422    422   
   423    423   #ifndef SYSCALL
   424    424   #  define SYSCALL sqlite3_syscall_ptr
   425    425   #endif
   426    426   
   427    427   /*
................................................................................
  1043   1043     { "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 },
  1044   1044   #else
  1045   1045     { "CreateFileMappingFromApp", (SYSCALL)0,                      0 },
  1046   1046   #endif
  1047   1047   
  1048   1048   #define osCreateFileMappingFromApp ((HANDLE(WINAPI*)(HANDLE, \
  1049   1049           LPSECURITY_ATTRIBUTES,ULONG,ULONG64,LPCWSTR))aSyscall[75].pCurrent)
         1050  +
         1051  +  { "InterlockedCompareExchange", (SYSCALL)InterlockedCompareExchange, 0 },
         1052  +
         1053  +#define osInterlockedCompareExchange ((LONG(WINAPI*)(LONG volatile*, \
         1054  +        LONG,LONG))aSyscall[76].pCurrent)
  1050   1055   
  1051   1056   }; /* End of the overrideable system calls */
  1052   1057   
  1053   1058   /*
  1054   1059   ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
  1055   1060   ** "win32" VFSes.  Return SQLITE_OK opon successfully updating the
  1056   1061   ** system call pointer, or SQLITE_NOTFOUND if there is no configurable
................................................................................
  1294   1299   #if !defined(SQLITE_WIN32_GETVERSIONEX) || !SQLITE_WIN32_GETVERSIONEX
  1295   1300   # define osIsNT()  (1)
  1296   1301   #elif SQLITE_OS_WINCE || SQLITE_OS_WINRT || !defined(SQLITE_WIN32_HAS_ANSI)
  1297   1302   # define osIsNT()  (1)
  1298   1303   #elif !defined(SQLITE_WIN32_HAS_WIDE)
  1299   1304   # define osIsNT()  (0)
  1300   1305   #else
  1301         -# define osIsNT()  (sqlite3_win32_is_nt())
         1306  +# define osIsNT()  ((sqlite3_os_type==2) || sqlite3_win32_is_nt())
  1302   1307   #endif
  1303   1308   
  1304   1309   /*
  1305   1310   ** This function determines if the machine is running a version of Windows
  1306   1311   ** based on the NT kernel.
  1307   1312   */
  1308   1313   int sqlite3_win32_is_nt(void){
  1309         -  if( sqlite3_os_type==0 ){
         1314  +  if( osInterlockedCompareExchange(&sqlite3_os_type, 0, 0)==0 ){
  1310   1315   #if defined(NTDDI_VERSION) && NTDDI_VERSION >= NTDDI_WIN8
  1311   1316       OSVERSIONINFOW sInfo;
  1312   1317       sInfo.dwOSVersionInfoSize = sizeof(sInfo);
  1313   1318       osGetVersionExW(&sInfo);
  1314   1319   #else
  1315   1320       OSVERSIONINFOA sInfo;
  1316   1321       sInfo.dwOSVersionInfoSize = sizeof(sInfo);
  1317   1322       osGetVersionExA(&sInfo);
  1318   1323   #endif
  1319         -    sqlite3_os_type = (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1;
         1324  +    osInterlockedCompareExchange(&sqlite3_os_type,
         1325  +        (sInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) ? 2 : 1, 0);
  1320   1326     }
  1321         -  return (sqlite3_os_type == 2);
         1327  +  return osInterlockedCompareExchange(&sqlite3_os_type, 2, 2)==2;
  1322   1328   }
  1323   1329   
  1324   1330   #ifdef SQLITE_WIN32_MALLOC
  1325   1331   /*
  1326   1332   ** Allocate nBytes of memory.
  1327   1333   */
  1328   1334   static void *winMemMalloc(int nBytes){
................................................................................
  5471   5477       winGetSystemCall,    /* xGetSystemCall */
  5472   5478       winNextSystemCall,   /* xNextSystemCall */
  5473   5479     };
  5474   5480   #endif
  5475   5481   
  5476   5482     /* Double-check that the aSyscall[] array has been constructed
  5477   5483     ** correctly.  See ticket [bb3a86e890c8e96ab] */
  5478         -  assert( ArraySize(aSyscall)==76 );
         5484  +  assert( ArraySize(aSyscall)==77 );
  5479   5485   
  5480   5486     /* get memory map allocation granularity */
  5481   5487     memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
  5482   5488   #if SQLITE_OS_WINRT
  5483   5489     osGetNativeSystemInfo(&winSysInfo);
  5484   5490   #else
  5485   5491     osGetSystemInfo(&winSysInfo);

Changes to src/test1.c.

  6577   6577     extern int sqlite3_opentemp_count;
  6578   6578     extern int sqlite3_like_count;
  6579   6579     extern int sqlite3_xferopt_count;
  6580   6580     extern int sqlite3_pager_readdb_count;
  6581   6581     extern int sqlite3_pager_writedb_count;
  6582   6582     extern int sqlite3_pager_writej_count;
  6583   6583   #if SQLITE_OS_WIN
  6584         -  extern int sqlite3_os_type;
         6584  +  extern LONG volatile sqlite3_os_type;
  6585   6585   #endif
  6586   6586   #ifdef SQLITE_DEBUG
  6587   6587     extern int sqlite3WhereTrace;
  6588   6588     extern int sqlite3OSTrace;
  6589   6589     extern int sqlite3WalTrace;
  6590   6590   #endif
  6591   6591   #ifdef SQLITE_TEST
................................................................................
  6635   6635   #endif
  6636   6636   #ifndef SQLITE_OMIT_UTF16
  6637   6637     Tcl_LinkVar(interp, "sqlite_last_needed_collation",
  6638   6638         (char*)&pzNeededCollation, TCL_LINK_STRING|TCL_LINK_READ_ONLY);
  6639   6639   #endif
  6640   6640   #if SQLITE_OS_WIN
  6641   6641     Tcl_LinkVar(interp, "sqlite_os_type",
  6642         -      (char*)&sqlite3_os_type, TCL_LINK_INT);
         6642  +      (char*)&sqlite3_os_type, TCL_LINK_LONG);
  6643   6643   #endif
  6644   6644   #ifdef SQLITE_TEST
  6645   6645     {
  6646   6646       static const char *query_plan = "*** OBSOLETE VARIABLE ***";
  6647   6647       Tcl_LinkVar(interp, "sqlite_query_plan",
  6648   6648          (char*)&query_plan, TCL_LINK_STRING|TCL_LINK_READ_ONLY);
  6649   6649     }