diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/os_unix.c | 16 | ||||
-rw-r--r-- | src/wal.c | 4 |
2 files changed, 12 insertions, 8 deletions
diff --git a/src/os_unix.c b/src/os_unix.c index cdba3d9f1..3b33edc93 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -3180,7 +3180,7 @@ struct unixShm { /* ** Constants used for locking */ -#define UNIX_SHM_BASE 80 /* Byte offset of the first lock byte */ +#define UNIX_SHM_BASE 81 /* Byte offset of the first lock byte */ #define UNIX_SHM_DMS 80 /* The deadman switch lock */ #ifdef SQLITE_DEBUG @@ -3241,13 +3241,13 @@ static int unixShmSystemLock( assert( n==1 || lockType!=F_RDLCK ); /* Locks are within range */ - assert( n>=1 && ofst>=0 && ofst+n<SQLITE_SHM_NLOCK ); + assert( n>=1 && n<SQLITE_SHM_NLOCK ); /* Initialize the locking parameters */ memset(&f, 0, sizeof(f)); f.l_type = lockType; f.l_whence = SEEK_SET; - f.l_start = ofst+UNIX_SHM_BASE; + f.l_start = ofst; f.l_len = n; rc = fcntl(pShmNode->h, F_SETLK, &f); @@ -3621,7 +3621,7 @@ static int unixShmLock( assert( pShmNode==pDbFd->pInode->pShmNode ); assert( pShmNode->pInode==pDbFd->pInode ); - assert( ofst>=0 && ofst+n<SQLITE_SHM_NLOCK ); + assert( ofst>=0 && ofst+n<=SQLITE_SHM_NLOCK ); assert( n>=1 ); assert( flags==(SQLITE_SHM_LOCK | SQLITE_SHM_SHARED) || flags==(SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE) @@ -3629,7 +3629,7 @@ static int unixShmLock( || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE) ); assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 ); - mask = (1<<(ofst+n+1)) - (1<<(ofst+1)); + mask = (1<<(ofst+n)) - (1<<ofst); assert( n>1 || mask==(1<<ofst) ); sqlite3_mutex_enter(pShmNode->mutex); if( flags & SQLITE_SHM_UNLOCK ){ @@ -3644,7 +3644,7 @@ static int unixShmLock( /* Unlock the system-level locks */ if( (mask & allMask)==0 ){ - rc = unixShmSystemLock(pShmNode, F_UNLCK, ofst+1, n); + rc = unixShmSystemLock(pShmNode, F_UNLCK, ofst+UNIX_SHM_BASE, n); }else{ rc = SQLITE_OK; } @@ -3673,7 +3673,7 @@ static int unixShmLock( /* Get shared locks at the system level, if necessary */ if( rc==SQLITE_OK ){ if( (allShared & mask)==0 ){ - rc = unixShmSystemLock(pShmNode, F_RDLCK, ofst+1, n); + rc = unixShmSystemLock(pShmNode, F_RDLCK, ofst+UNIX_SHM_BASE, n); }else{ rc = SQLITE_OK; } @@ -3699,7 +3699,7 @@ static int unixShmLock( ** also mark the local connection as being locked. */ if( rc==SQLITE_OK ){ - rc = unixShmSystemLock(pShmNode, F_WRLCK, ofst+1, n); + rc = unixShmSystemLock(pShmNode, F_WRLCK, ofst+UNIX_SHM_BASE, n); if( rc==SQLITE_OK ){ p->sharedMask &= ~mask; p->exclMask |= mask; @@ -1933,6 +1933,7 @@ int sqlite3WalBeginWriteTransaction(Wal *pWal){ if( rc ){ return rc; } + pWal->writeLock = 1; /* If another connection has written to the database file since the ** time the read transaction on this connection was started, then @@ -1941,10 +1942,12 @@ int sqlite3WalBeginWriteTransaction(Wal *pWal){ rc = walIndexMap(pWal, pWal->hdr.mxFrame); if( rc ){ walUnlockExclusive(pWal, WAL_WRITE_LOCK, 1); + pWal->writeLock = 0; return rc; } if( memcmp(&pWal->hdr, (void*)pWal->pWiData, sizeof(WalIndexHdr))!=0 ){ walUnlockExclusive(pWal, WAL_WRITE_LOCK, 1); + pWal->writeLock = 0; walIndexUnmap(pWal); return SQLITE_BUSY; } @@ -1968,6 +1971,7 @@ int sqlite3WalBeginWriteTransaction(Wal *pWal){ walUnlockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1); } walUnlockShared(pWal, WAL_READ_LOCK(0)); + pWal->readLock = -1; do{ int notUsed; rc = walTryBeginRead(pWal, ¬Used, 1); |