mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-12 13:01:09 +03:00
Avoid a race condition that might cause a busy_timeout to last longer than
it should. FossilOrigin-Name: b81960561b47a1b49646f2f8870dd0684dc4ca7c0b9e11076fd713de66b75972
This commit is contained in:
@@ -1490,18 +1490,15 @@ static int osSetPosixAdvisoryLock(
|
||||
unixFile *pFile /* Structure holding timeout value */
|
||||
){
|
||||
int rc = osFcntl(h,F_SETLK,pLock);
|
||||
if( rc<0 && pFile->iBusyTimeout>0 ){
|
||||
while( rc<0 && pFile->iBusyTimeout>0 ){
|
||||
/* On systems that support some kind of blocking file lock with a timeout,
|
||||
** make appropriate changes here to invoke that blocking file lock. On
|
||||
** generic posix, however, there is no such API. So we simply try the
|
||||
** lock once every millisecond until either the timeout expires, or until
|
||||
** the lock is obtained. */
|
||||
do{
|
||||
usleep(1000);
|
||||
rc = osFcntl(h,F_SETLK,pLock);
|
||||
pFile->iBusyTimeout--;
|
||||
}while( rc<0 && pFile->iBusyTimeout>0 );
|
||||
pFile->iBusyTimeout = 0;
|
||||
usleep(1000);
|
||||
rc = osFcntl(h,F_SETLK,pLock);
|
||||
pFile->iBusyTimeout--;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user