diff options
author | dan <Dan Kennedy> | 2021-04-02 19:55:48 +0000 |
---|---|---|
committer | dan <Dan Kennedy> | 2021-04-02 19:55:48 +0000 |
commit | aecc04d64269c8e798e98b1f049f2b974763fd92 (patch) | |
tree | 5047999f0ede0b7d439c3acc6359f5fa6f6c07c6 /src/os_unix.c | |
parent | ec435c40ed847ee806aacaba59909256d969ac7b (diff) | |
download | sqlite-aecc04d64269c8e798e98b1f049f2b974763fd92.tar.gz sqlite-aecc04d64269c8e798e98b1f049f2b974763fd92.zip |
Add experimental SQLITE_FCNTL_EXTERNAL_READER file control.
FossilOrigin-Name: e16da5af822ef31d7e05992403cf9787fbb3d9abb0b5283aba55ea07e1830a72
Diffstat (limited to 'src/os_unix.c')
-rw-r--r-- | src/os_unix.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/os_unix.c b/src/os_unix.c index e3cfe35cd..adc89f5a7 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -3951,6 +3951,7 @@ static void unixModeBit(unixFile *pFile, unsigned char mask, int *pArg){ /* Forward declaration */ static int unixGetTempname(int nBuf, char *zBuf); +static int unixFcntlExternalReader(unixFile*, int*); /* ** Information and control of an open file handle. @@ -4067,6 +4068,10 @@ static int unixFileControl(sqlite3_file *id, int op, void *pArg){ return proxyFileControl(id,op,pArg); } #endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) */ + + case SQLITE_FCNTL_EXTERNAL_READER: { + return unixFcntlExternalReader((unixFile*)id, (int*)pArg); + } } return SQLITE_NOTFOUND; } @@ -4313,6 +4318,40 @@ struct unixShm { #define UNIX_SHM_DMS (UNIX_SHM_BASE+SQLITE_SHM_NLOCK) /* deadman switch */ /* +** Use F_GETLK to check whether or not there are any readers with open +** wal-mode transactions in other processes on database file pFile. If +** no error occurs, return SQLITE_OK and set (*piOut) to 1 if there are +** such transactions, or 0 otherwise. If an error occurs, return an +** SQLite error code. The final value of *piOut is undefined in this +** case. +*/ +static int unixFcntlExternalReader(unixFile *pFile, int *piOut){ + int rc = SQLITE_OK; + *piOut = 0; + if( pFile->pShm){ + unixShmNode *pShmNode = pFile->pShm->pShmNode; + struct flock f; + + memset(&f, 0, sizeof(f)); + f.l_type = F_WRLCK; + f.l_whence = SEEK_SET; + f.l_start = UNIX_SHM_BASE + 3; + f.l_len = SQLITE_SHM_NLOCK - 3; + + sqlite3_mutex_enter(pShmNode->pShmMutex); + if( osFcntl(pShmNode->hShm, F_GETLK, &f)<0 ){ + rc = SQLITE_IOERR_LOCK; + }else{ + *piOut = (f.l_type!=F_UNLCK); + } + sqlite3_mutex_leave(pShmNode->pShmMutex); + } + + return rc; +} + + +/* ** Apply posix advisory locks for all bytes from ofst through ofst+n-1. ** ** Locks block if the mask is exactly UNIX_SHM_C and are non-blocking |