/ Check-in [e9bfa6e4]
Login

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

Overview
Comment:Further simplifications to the SHM locking logic. Remove the SQLITE_SHM_QUERY option. Unify the WRITE to READ and RECOVER to READ transitions.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e9bfa6e4ce7d1edc6be8b9173ac3b6bfd180632a
User & Date: drh 2010-05-05 19:09:49
Context
2010-05-05
20:00
Change the behavior of the sqlite3_wal_hook() callback. It should now return SQLITE_OK or an error code and the error code is propagated back up the stack. If a checkpoint is desired, the callback should invoke sqlite3_wal_callback() itself. check-in: 1b14195e user: drh tags: trunk
19:09
Further simplifications to the SHM locking logic. Remove the SQLITE_SHM_QUERY option. Unify the WRITE to READ and RECOVER to READ transitions. check-in: e9bfa6e4 user: drh tags: trunk
19:04
Test the handling of errors returned by the xShmXXX() APIs. check-in: 72663123 user: dan tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
....
5316
5317
5318
5319
5320
5321
5322

5323

5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338

  UNUSED_PARAMETER(pVfs);

  /* Note that SQLITE_SHM_READ_FULL and SQLITE_SHM_PENDING are never
  ** directly requested; they are side effects from requesting
  ** SQLITE_SHM_READ and SQLITE_SHM_CHECKPOINT, respectively.
  */
  assert( desiredLock==SQLITE_SHM_QUERY
       || desiredLock==SQLITE_SHM_UNLOCK
       || desiredLock==SQLITE_SHM_READ
       || desiredLock==SQLITE_SHM_WRITE
       || desiredLock==SQLITE_SHM_CHECKPOINT
       || desiredLock==SQLITE_SHM_RECOVER );

  /* Return directly if this is just a lock state query, or if
  ** the connection is already in the desired locking state.
  */
  if( desiredLock==SQLITE_SHM_QUERY
   || desiredLock==p->lockState
   || (desiredLock==SQLITE_SHM_READ && p->lockState==SQLITE_SHM_READ_FULL)
  ){
    OSTRACE(("SHM-LOCK shmid-%d, pid-%d request %s and got %s\n",
             p->id, getpid(), azLkName[desiredLock], azLkName[p->lockState]));
    if( pGotLock ) *pGotLock = p->lockState;
    return SQLITE_OK;
  }
................................................................................
              p->lockState = SQLITE_SHM_READ_FULL;
            }
          }else{
            unixShmUnlock(pFile, p, UNIX_SHM_B);
            p->lockState = SQLITE_SHM_READ;
          }
        }

      }else if( p->lockState==SQLITE_SHM_WRITE ){

        rc = unixShmSharedLock(pFile, p, UNIX_SHM_A);
        unixShmUnlock(pFile, p, UNIX_SHM_C|UNIX_SHM_D);
        p->lockState = SQLITE_SHM_READ;
      }else{
        assert( p->lockState==SQLITE_SHM_RECOVER );
        unixShmUnlock(pFile, p, UNIX_SHM_C);
        p->lockState = SQLITE_SHM_READ;
        rc = SQLITE_OK;
      }
      break;
    }
    case SQLITE_SHM_WRITE: {
      assert( p->lockState==SQLITE_SHM_READ 
              || p->lockState==SQLITE_SHM_READ_FULL );
      rc = unixShmExclusiveLock(pFile, p, UNIX_SHM_C|UNIX_SHM_D);







<
|








<
|







 







>
|
>



<
<
<
<
<







5262
5263
5264
5265
5266
5267
5268

5269
5270
5271
5272
5273
5274
5275
5276
5277

5278
5279
5280
5281
5282
5283
5284
5285
....
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326





5327
5328
5329
5330
5331
5332
5333

  UNUSED_PARAMETER(pVfs);

  /* Note that SQLITE_SHM_READ_FULL and SQLITE_SHM_PENDING are never
  ** directly requested; they are side effects from requesting
  ** SQLITE_SHM_READ and SQLITE_SHM_CHECKPOINT, respectively.
  */

  assert( desiredLock==SQLITE_SHM_UNLOCK
       || desiredLock==SQLITE_SHM_READ
       || desiredLock==SQLITE_SHM_WRITE
       || desiredLock==SQLITE_SHM_CHECKPOINT
       || desiredLock==SQLITE_SHM_RECOVER );

  /* Return directly if this is just a lock state query, or if
  ** the connection is already in the desired locking state.
  */

  if( desiredLock==p->lockState
   || (desiredLock==SQLITE_SHM_READ && p->lockState==SQLITE_SHM_READ_FULL)
  ){
    OSTRACE(("SHM-LOCK shmid-%d, pid-%d request %s and got %s\n",
             p->id, getpid(), azLkName[desiredLock], azLkName[p->lockState]));
    if( pGotLock ) *pGotLock = p->lockState;
    return SQLITE_OK;
  }
................................................................................
              p->lockState = SQLITE_SHM_READ_FULL;
            }
          }else{
            unixShmUnlock(pFile, p, UNIX_SHM_B);
            p->lockState = SQLITE_SHM_READ;
          }
        }
      }else{
       assert( p->lockState==SQLITE_SHM_WRITE
               || p->lockState==SQLITE_SHM_RECOVER );
        rc = unixShmSharedLock(pFile, p, UNIX_SHM_A);
        unixShmUnlock(pFile, p, UNIX_SHM_C|UNIX_SHM_D);
        p->lockState = SQLITE_SHM_READ;





      }
      break;
    }
    case SQLITE_SHM_WRITE: {
      assert( p->lockState==SQLITE_SHM_READ 
              || p->lockState==SQLITE_SHM_READ_FULL );
      rc = unixShmExclusiveLock(pFile, p, UNIX_SHM_C|UNIX_SHM_D);

Changes to src/sqlite.h.in.

875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
#define SQLITE_ACCESS_READWRITE 1
#define SQLITE_ACCESS_READ      2

/*
** CAPI3REF: Flags for the xShmLock VFS method
**
** These integer constants define the various locking states that
** an sqlite3_shm object can be in.  The SQLITE_SHM_QUERY integer
** is not a valid data - it is a constant pasted to the 
** sqlite3_vfs.xShmLock() method for querying the current lock
** state.
*/
#define SQLITE_SHM_UNLOCK       0
#define SQLITE_SHM_READ         1
#define SQLITE_SHM_READ_FULL    2
#define SQLITE_SHM_WRITE        3
#define SQLITE_SHM_PENDING      4
#define SQLITE_SHM_CHECKPOINT   5
#define SQLITE_SHM_RECOVER      6
#define SQLITE_SHM_QUERY        (-1)

/*
** CAPI3REF: Initialize The SQLite Library
**
** ^The sqlite3_initialize() routine initializes the
** SQLite library.  ^The sqlite3_shutdown() routine
** deallocates any resources that were allocated by sqlite3_initialize().







|
<
<
<








<







875
876
877
878
879
880
881
882



883
884
885
886
887
888
889
890

891
892
893
894
895
896
897
#define SQLITE_ACCESS_READWRITE 1
#define SQLITE_ACCESS_READ      2

/*
** CAPI3REF: Flags for the xShmLock VFS method
**
** These integer constants define the various locking states that
** an sqlite3_shm object can be in.



*/
#define SQLITE_SHM_UNLOCK       0
#define SQLITE_SHM_READ         1
#define SQLITE_SHM_READ_FULL    2
#define SQLITE_SHM_WRITE        3
#define SQLITE_SHM_PENDING      4
#define SQLITE_SHM_CHECKPOINT   5
#define SQLITE_SHM_RECOVER      6


/*
** CAPI3REF: Initialize The SQLite Library
**
** ^The sqlite3_initialize() routine initializes the
** SQLite library.  ^The sqlite3_shutdown() routine
** deallocates any resources that were allocated by sqlite3_initialize().