Skip to content

Commit

Permalink
Fix in-memory database locking
Browse files Browse the repository at this point in the history
  • Loading branch information
otoolep committed Dec 6, 2022
1 parent 7116c96 commit 4dde487
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion sqlite3-binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -50141,15 +50141,28 @@ static int memdbFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
** Lock an memdb-file.
*/
static int memdbLock(sqlite3_file *pFile, int eLock){
MemFile *pThis = (MemFile*)pFile;
MemFile *pThis = (MemFile*)pFile;
MemStore *p = pThis->pStore;
int rc = SQLITE_OK;
if( eLock==pThis->eLock ) return SQLITE_OK;
memdbEnter(p);
if( eLock>SQLITE_LOCK_SHARED ){
assert( pThis->eLock>=SQLITE_LOCK_SHARED );
if( p->mFlags & SQLITE_DESERIALIZE_READONLY ){
rc = SQLITE_READONLY;
}else if( eLock==SQLITE_LOCK_EXCLUSIVE ){
/* Taking an EXCLUSIVE lock. Fail if we only have SHARED and any
** other client has any kind of write-lock. Also fail if any other
** client is holding read-lock. */
if( pThis->eLock<=SQLITE_LOCK_SHARED && p->nWrLock ){
rc = SQLITE_BUSY;
}else if( p->nRdLock>1 ){
rc = SQLITE_BUSY;
}
p->nWrLock = 1;
}else if( pThis->eLock<=SQLITE_LOCK_SHARED ){
/* Upgrading to RESERVED or PENDING from SHARED. Fail if any other
** client has a write-lock of any kind. */
if( p->nWrLock ){
rc = SQLITE_BUSY;
}else{
Expand Down

0 comments on commit 4dde487

Please sign in to comment.