/ Check-in [4df6e247]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Further corrections to the Win32 interface for lsm1.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 4df6e2476ce93b9ca7a6959c8c2d6ef2c30395984b007d74166031dcf09d54b4
User & Date: mistachkin 2017-06-29 15:13:48
Context
2017-06-29
15:24
Add interfaces sqlite3_prepare_v3() and sqlite3_prepare16_v3() with the extra prepFlags argument. Add the SQLITE_PREPARE_PERSISTENT option as one bit in that argument. Use the new option in FTS3, FTS5, and RTREE. check-in: 03977248 user: drh tags: trunk
15:13
Further corrections to the Win32 interface for lsm1. check-in: 4df6e247 user: mistachkin tags: trunk
14:33
Rename the "stmts" virtual table to just "stmt" without the final "s". check-in: adfdb801 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/lsm1/lsm_win32.c.

   567    567     lsmFree(pEnv, zConverted);
   568    568     return rc;
   569    569   }
   570    570   
   571    571   static int lsmWin32OsUnlink(lsm_env *pEnv, const char *zFile){
   572    572     return win32Delete(pEnv, zFile);
   573    573   }
          574  +
          575  +#if !defined(win32IsLockBusy)
          576  +#define win32IsLockBusy(a) (((a)==ERROR_LOCK_VIOLATION) || \
          577  +                            ((a)==ERROR_IO_PENDING))
          578  +#endif
   574    579   
   575    580   int lsmWin32OsLock(lsm_file *pFile, int iLock, int eType){
   576    581     Win32File *pWin32File = (Win32File *)pFile;
   577    582     OVERLAPPED ovlp;
   578    583   
   579    584     assert( LSM_LOCK_UNLOCK==0 );
   580    585     assert( LSM_LOCK_SHARED==1 );
................................................................................
   584    589   
   585    590     memset(&ovlp, 0, sizeof(OVERLAPPED));
   586    591     ovlp.Offset = (4096-iLock);
   587    592     if( eType>LSM_LOCK_UNLOCK ){
   588    593       DWORD flags = LOCKFILE_FAIL_IMMEDIATELY;
   589    594       if( eType>=LSM_LOCK_EXCL ) flags |= LOCKFILE_EXCLUSIVE_LOCK;
   590    595       if( !LockFileEx(pWin32File->hFile, flags, 0, 1, 0, &ovlp) ){
   591         -      if( GetLastError()==ERROR_IO_PENDING ){
          596  +      if( win32IsLockBusy(GetLastError()) ){
   592    597           return LSM_BUSY;
   593    598         }else{
   594    599           return LSM_IOERR_BKPT;
   595    600         }
   596    601       }
   597    602     }else{
   598    603       if( !UnlockFileEx(pWin32File->hFile, 0, 1, 0, &ovlp) ){
................................................................................
   614    619     assert( nLock>=0 );
   615    620     assert( iLock>0 && iLock<=32 );
   616    621   
   617    622     if( eType>=LSM_LOCK_EXCL ) flags |= LOCKFILE_EXCLUSIVE_LOCK;
   618    623     memset(&ovlp, 0, sizeof(OVERLAPPED));
   619    624     ovlp.Offset = (4096-iLock);
   620    625     if( !LockFileEx(pWin32File->hFile, flags, 0, (DWORD)nLock, 0, &ovlp) ){
   621         -    if( GetLastError()==ERROR_IO_PENDING ){
          626  +    if( win32IsLockBusy(GetLastError()) ){
   622    627         return LSM_BUSY;
   623    628       }else{
   624    629         return LSM_IOERR_BKPT;
   625    630       }
   626    631     }
   627    632     UnlockFileEx(pWin32File->hFile, 0, (DWORD)nLock, 0, &ovlp);
   628    633     return LSM_OK;
................................................................................
   682    687         apNew[i] = NULL;
   683    688       }
   684    689       pWin32File->ahShm = ahNew;
   685    690       pWin32File->apShm = apNew;
   686    691       pWin32File->nShm = nNew;
   687    692     }
   688    693   
   689         -  if( pWin32File->apShm[iChunk]==NULL ){
          694  +  if( pWin32File->ahShm[iChunk]==NULL ){
   690    695       HANDLE hMap;
   691         -    LPVOID pMap;
   692    696       hMap = CreateFileMappingW(pWin32File->hShmFile, NULL, PAGE_READWRITE, 0,
   693    697                                 (DWORD)sz, NULL);
   694    698       if( hMap==NULL ){
   695    699         return LSM_IOERR_BKPT;
   696    700       }
   697    701       pWin32File->ahShm[iChunk] = hMap;
   698         -    pMap = MapViewOfFile(hMap, FILE_MAP_WRITE | FILE_MAP_READ, 0, 0,
   699         -                         (SIZE_T)sz);
          702  +  }
          703  +  if( pWin32File->apShm[iChunk]==NULL ){
          704  +    LPVOID pMap;
          705  +    pMap = MapViewOfFile(pWin32File->ahShm[iChunk],
          706  +                         FILE_MAP_WRITE | FILE_MAP_READ, 0, 0, (SIZE_T)sz);
   700    707       if( pMap==NULL ){
   701    708         return LSM_IOERR_BKPT;
   702    709       }
   703    710       pWin32File->apShm[iChunk] = pMap;
   704         -    pWin32File->nMap = (SIZE_T)sz;
   705    711     }
   706    712     *ppShm = pWin32File->apShm[iChunk];
   707    713     return LSM_OK;
   708    714   }
   709    715   
   710    716   void lsmWin32OsShmBarrier(void){
   711    717     MemoryBarrier();