/ Check-in [bf7eda67]
Login

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

Overview
Comment:Minor cleanup and refactoring of the Win32 VFS for lsm1.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: bf7eda67c8124c3cd5d9150f2f2694cd3f991b20e0a527398885976d0d787242
User & Date: mistachkin 2017-07-10 20:33:50
Context
2017-07-10
20:39
Fix errors in comments in the STMT virtual table. No code changes. check-in: 9a8f045d user: drh tags: trunk
20:33
Minor cleanup and refactoring of the Win32 VFS for lsm1. check-in: bf7eda67 user: mistachkin tags: trunk
19:54
Another spelling error in the README.md file. check-in: 05129374 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/lsm1/lsm_win32.c.

   583    583   }
   584    584   
   585    585   #if !defined(win32IsLockBusy)
   586    586   #define win32IsLockBusy(a) (((a)==ERROR_LOCK_VIOLATION) || \
   587    587                               ((a)==ERROR_IO_PENDING))
   588    588   #endif
   589    589   
   590         -static int lsmWin32OsLock(lsm_file *pFile, int iLock, int eType){
   591         -  Win32File *pWin32File = (Win32File *)pFile;
          590  +static int win32LockFile(
          591  +  Win32File *pWin32File,
          592  +  int iLock,
          593  +  int nLock,
          594  +  int eType
          595  +){
   592    596     OVERLAPPED ovlp;
   593    597   
   594    598     assert( LSM_LOCK_UNLOCK==0 );
   595    599     assert( LSM_LOCK_SHARED==1 );
   596    600     assert( LSM_LOCK_EXCL==2 );
   597    601     assert( eType>=LSM_LOCK_UNLOCK && eType<=LSM_LOCK_EXCL );
          602  +  assert( nLock>=0 );
   598    603     assert( iLock>0 && iLock<=32 );
   599    604   
   600    605     memset(&ovlp, 0, sizeof(OVERLAPPED));
   601         -  ovlp.Offset = (4096-iLock);
          606  +  ovlp.Offset = (4096-iLock-nLock+1);
   602    607     if( eType>LSM_LOCK_UNLOCK ){
   603    608       DWORD flags = LOCKFILE_FAIL_IMMEDIATELY;
   604    609       if( eType>=LSM_LOCK_EXCL ) flags |= LOCKFILE_EXCLUSIVE_LOCK;
   605         -    if( !LockFileEx(pWin32File->hFile, flags, 0, 1, 0, &ovlp) ){
          610  +    if( !LockFileEx(pWin32File->hFile, flags, 0, (DWORD)nLock, 0, &ovlp) ){
   606    611         if( win32IsLockBusy(GetLastError()) ){
   607    612           return LSM_BUSY;
   608    613         }else{
   609    614           return LSM_IOERR_BKPT;
   610    615         }
   611    616       }
   612    617     }else{
   613         -    if( !UnlockFileEx(pWin32File->hFile, 0, 1, 0, &ovlp) ){
          618  +    if( !UnlockFileEx(pWin32File->hFile, 0, (DWORD)nLock, 0, &ovlp) ){
   614    619         return LSM_IOERR_BKPT;
   615    620       }
   616    621     }
   617    622     return LSM_OK;
   618    623   }
          624  +
          625  +static int lsmWin32OsLock(lsm_file *pFile, int iLock, int eType){
          626  +  Win32File *pWin32File = (Win32File *)pFile;
          627  +  return win32LockFile(pWin32File, iLock, 1, eType);
          628  +}
   619    629   
   620    630   static int lsmWin32OsTestLock(lsm_file *pFile, int iLock, int nLock, int eType){
          631  +  int rc;
   621    632     Win32File *pWin32File = (Win32File *)pFile;
   622         -  DWORD flags = LOCKFILE_FAIL_IMMEDIATELY;
   623         -  OVERLAPPED ovlp;
   624         -
   625         -  assert( LSM_LOCK_UNLOCK==0 );
   626         -  assert( LSM_LOCK_SHARED==1 );
   627         -  assert( LSM_LOCK_EXCL==2 );
   628         -  assert( eType==LSM_LOCK_SHARED || eType==LSM_LOCK_EXCL );
   629         -  assert( nLock>=0 );
   630         -  assert( iLock>0 && iLock<=32 );
   631         -
   632         -  if( eType>=LSM_LOCK_EXCL ) flags |= LOCKFILE_EXCLUSIVE_LOCK;
   633         -  memset(&ovlp, 0, sizeof(OVERLAPPED));
   634         -  ovlp.Offset = (4096-iLock-nLock+1);
   635         -  if( !LockFileEx(pWin32File->hFile, flags, 0, (DWORD)nLock, 0, &ovlp) ){
   636         -    if( win32IsLockBusy(GetLastError()) ){
   637         -      return LSM_BUSY;
   638         -    }else{
   639         -      return LSM_IOERR_BKPT;
   640         -    }
   641         -  }
   642         -  UnlockFileEx(pWin32File->hFile, 0, (DWORD)nLock, 0, &ovlp);
          633  +  rc = win32LockFile(pWin32File, iLock, nLock, eType);
          634  +  if( rc!=LSM_OK ) return rc;
          635  +  win32LockFile(pWin32File, iLock, nLock, LSM_LOCK_UNLOCK);
   643    636     return LSM_OK;
   644    637   }
   645    638   
   646    639   static int lsmWin32OsShmMap(lsm_file *pFile, int iChunk, int sz, void **ppShm){
   647    640     int rc;
   648    641     Win32File *pWin32File = (Win32File *)pFile;
   649    642     int iOffset = iChunk * sz;