mirror of
https://github.com/sqlite/sqlite.git
synced 2025-12-21 13:38:01 +03:00
Merge trunk into wasi-patches branch.
FossilOrigin-Name: 656d36f50f630da68262469087bad1ac71b10325e233a7963103c8cbc232f61a
This commit is contained in:
@@ -1695,7 +1695,7 @@ static int unixFileLock(unixFile *pFile, struct flock *pLock){
|
||||
**
|
||||
** UNLOCKED -> SHARED
|
||||
** SHARED -> RESERVED
|
||||
** SHARED -> (PENDING) -> EXCLUSIVE
|
||||
** SHARED -> EXCLUSIVE
|
||||
** RESERVED -> (PENDING) -> EXCLUSIVE
|
||||
** PENDING -> EXCLUSIVE
|
||||
**
|
||||
@@ -1728,19 +1728,20 @@ static int unixLock(sqlite3_file *id, int eFileLock){
|
||||
** A RESERVED lock is implemented by grabbing a write-lock on the
|
||||
** 'reserved byte'.
|
||||
**
|
||||
** A process may only obtain a PENDING lock after it has obtained a
|
||||
** SHARED lock. A PENDING lock is implemented by obtaining a write-lock
|
||||
** on the 'pending byte'. This ensures that no new SHARED locks can be
|
||||
** obtained, but existing SHARED locks are allowed to persist. A process
|
||||
** does not have to obtain a RESERVED lock on the way to a PENDING lock.
|
||||
** This property is used by the algorithm for rolling back a journal file
|
||||
** after a crash.
|
||||
** An EXCLUSIVE lock may only be requested after either a SHARED or
|
||||
** RESERVED lock is held. An EXCLUSIVE lock is implemented by obtaining
|
||||
** a write-lock on the entire 'shared byte range'. Since all other locks
|
||||
** require a read-lock on one of the bytes within this range, this ensures
|
||||
** that no other locks are held on the database.
|
||||
**
|
||||
** An EXCLUSIVE lock, obtained after a PENDING lock is held, is
|
||||
** implemented by obtaining a write-lock on the entire 'shared byte
|
||||
** range'. Since all other locks require a read-lock on one of the bytes
|
||||
** within this range, this ensures that no other locks are held on the
|
||||
** database.
|
||||
** If a process that holds a RESERVED lock requests an EXCLUSIVE, then
|
||||
** a PENDING lock is obtained first. A PENDING lock is implemented by
|
||||
** obtaining a write-lock on the 'pending byte'. This ensures that no new
|
||||
** SHARED locks can be obtained, but existing SHARED locks are allowed to
|
||||
** persist. If the call to this function fails to obtain the EXCLUSIVE
|
||||
** lock in this case, it holds the PENDING lock intead. The client may
|
||||
** then re-attempt the EXCLUSIVE lock later on, after existing SHARED
|
||||
** locks have cleared.
|
||||
*/
|
||||
int rc = SQLITE_OK;
|
||||
unixFile *pFile = (unixFile*)id;
|
||||
@@ -1811,7 +1812,7 @@ static int unixLock(sqlite3_file *id, int eFileLock){
|
||||
lock.l_len = 1L;
|
||||
lock.l_whence = SEEK_SET;
|
||||
if( eFileLock==SHARED_LOCK
|
||||
|| (eFileLock==EXCLUSIVE_LOCK && pFile->eFileLock<PENDING_LOCK)
|
||||
|| (eFileLock==EXCLUSIVE_LOCK && pFile->eFileLock==RESERVED_LOCK)
|
||||
){
|
||||
lock.l_type = (eFileLock==SHARED_LOCK?F_RDLCK:F_WRLCK);
|
||||
lock.l_start = PENDING_BYTE;
|
||||
@@ -1822,6 +1823,9 @@ static int unixLock(sqlite3_file *id, int eFileLock){
|
||||
storeLastErrno(pFile, tErrno);
|
||||
}
|
||||
goto end_lock;
|
||||
}else if( eFileLock==EXCLUSIVE_LOCK ){
|
||||
pFile->eFileLock = PENDING_LOCK;
|
||||
pInode->eFileLock = PENDING_LOCK;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1909,13 +1913,9 @@ static int unixLock(sqlite3_file *id, int eFileLock){
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
pFile->eFileLock = eFileLock;
|
||||
pInode->eFileLock = eFileLock;
|
||||
}else if( eFileLock==EXCLUSIVE_LOCK ){
|
||||
pFile->eFileLock = PENDING_LOCK;
|
||||
pInode->eFileLock = PENDING_LOCK;
|
||||
}
|
||||
|
||||
end_lock:
|
||||
|
||||
Reference in New Issue
Block a user