aboutsummaryrefslogtreecommitdiff
path: root/src/os_unix.c
diff options
context:
space:
mode:
authordan <dan@noemail.net>2020-05-06 20:27:18 +0000
committerdan <dan@noemail.net>2020-05-06 20:27:18 +0000
commit7bb8b8a4f743c1bab707a01ba61c7f1fe3695195 (patch)
treed5f6b07d1337e92abbbd857fd1b4ebec4525424b /src/os_unix.c
parentfc87ab8c4ab229a2adae3297148eb3ebdad1134f (diff)
downloadsqlite-7bb8b8a4f743c1bab707a01ba61c7f1fe3695195.tar.gz
sqlite-7bb8b8a4f743c1bab707a01ba61c7f1fe3695195.zip
Add error code SQLITE_BUSY_TIMEOUT, used internally by the OS layer to indicate that a call to xShmLock() has failed due to timeout of a blocking lock.
FossilOrigin-Name: f3ef9c7c2b4ba3de1057ad569f068b241d5f23e6629d8e0dacf85e57fd13b8aa
Diffstat (limited to 'src/os_unix.c')
-rw-r--r--src/os_unix.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/os_unix.c b/src/os_unix.c
index 72c446ea7..fb172e721 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -1565,8 +1565,9 @@ static int osSetPosixAdvisoryLock(
struct flock *pLock, /* The description of the lock */
unixFile *pFile /* Structure holding timeout value */
){
+ int tm = pFile->iBusyTimeout;
int rc = osFcntl(h,F_SETLK,pLock);
- while( rc<0 && pFile->iBusyTimeout>0 ){
+ while( rc<0 && tm>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
@@ -1574,7 +1575,7 @@ static int osSetPosixAdvisoryLock(
** the lock is obtained. */
usleep(1000);
rc = osFcntl(h,F_SETLK,pLock);
- pFile->iBusyTimeout--;
+ tm--;
}
return rc;
}
@@ -4316,13 +4317,16 @@ static int unixShmSystemLock(
assert( n>=1 && n<=SQLITE_SHM_NLOCK );
if( pShmNode->hShm>=0 ){
+ int res;
/* Initialize the locking parameters */
f.l_type = lockType;
f.l_whence = SEEK_SET;
f.l_start = ofst;
f.l_len = n;
- rc = osSetPosixAdvisoryLock(pShmNode->hShm, &f, pFile);
- rc = (rc!=(-1)) ? SQLITE_OK : SQLITE_BUSY;
+ res = osSetPosixAdvisoryLock(pShmNode->hShm, &f, pFile);
+ if( res==-1 ){
+ rc = (pFile->iBusyTimeout ? SQLITE_BUSY_TIMEOUT : SQLITE_BUSY);
+ }
}
/* Update the global lock state and do debug tracing */