mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-11 01:42:22 +03:00
Add experimental SQLITE_FCNTL_EXTERNAL_READER file control.
FossilOrigin-Name: e16da5af822ef31d7e05992403cf9787fbb3d9abb0b5283aba55ea07e1830a72
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -4312,6 +4317,40 @@ struct unixShm {
|
||||
#define UNIX_SHM_BASE ((22+SQLITE_SHM_NLOCK)*4) /* first lock byte */
|
||||
#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.
|
||||
**
|
||||
|
||||
Reference in New Issue
Block a user