1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-12 13:01:09 +03:00

Fix comments and refactor some names associated with shared-memory locking

in the Unix VFS.  No logical changes.

FossilOrigin-Name: 3e9f1635271c92dce5324728b4ee1cc1a1856ec3c60b1b512a652c21e010e63e
This commit is contained in:
drh
2018-10-02 19:36:40 +00:00
parent ba160891de
commit 24efa5444d
3 changed files with 38 additions and 38 deletions

View File

@@ -1,5 +1,5 @@
C Add\sthe\s"PRAGMA\stable_xinfo"\scommand\sthat\sworks\slike\stable_info\sbut\salso\nshows\shidden\scolumns\sin\svirtual\stables\sand\sadds\sthe\s"hidden"\sboolean\scolumn. C Fix\scomments\sand\srefactor\ssome\snames\sassociated\swith\sshared-memory\slocking\nin\sthe\sUnix\sVFS.\s\sNo\slogical\schanges.
D 2018-10-01T21:41:15.265 D 2018-10-02T19:36:40.212
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F Makefile.in 01e95208a78b57d056131382c493c963518f36da4c42b12a97eb324401b3a334 F Makefile.in 01e95208a78b57d056131382c493c963518f36da4c42b12a97eb324401b3a334
@@ -487,7 +487,7 @@ F src/os.c 8aeb0b0f40f8f5b0da03fe49706695adaf42d2f516ab95abc72e86c245e119de
F src/os.h 48388821692e87da174ea198bf96b1b2d9d83be5dfc908f673ee21fafbe0d432 F src/os.h 48388821692e87da174ea198bf96b1b2d9d83be5dfc908f673ee21fafbe0d432
F src/os_common.h b2f4707a603e36811d9b1a13278bffd757857b85 F src/os_common.h b2f4707a603e36811d9b1a13278bffd757857b85
F src/os_setup.h 0dbaea40a7d36bf311613d31342e0b99e2536586 F src/os_setup.h 0dbaea40a7d36bf311613d31342e0b99e2536586
F src/os_unix.c 7cfd67db0e2f926243f646db7ec1caa33ca9bee45799b0160ddfcd6ccfc175d2 F src/os_unix.c 3acd41af1334d7d2af8ca8ce684ccc73eeab7fe907ddab630963fd54102b4be4
F src/os_win.c 070cdbb400097c6cda54aa005356095afdc2f3ee691d17192c54724ef146a971 F src/os_win.c 070cdbb400097c6cda54aa005356095afdc2f3ee691d17192c54724ef146a971
F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a
F src/pager.c a0d8f686ef64549ad5b356fd30429bd9ee7a06dd42b4d6faa096352ff26b1c5b F src/pager.c a0d8f686ef64549ad5b356fd30429bd9ee7a06dd42b4d6faa096352ff26b1c5b
@@ -1770,8 +1770,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 310b4b65b8c8ee080760c7efb4c7e20244c6063a5dba37a4f40490105aafd29f 7694b9bc3003db6ba0b41c5029c8f7b84c07724e7a518e835e98b3c46e4ea227 P defa0515b8fd50ed9be699542f8c6695dd4a60c02f310665db6657ec5b6b67d0
R 4421b937cd53dd313f71ab5caa0a0109 R 9097a8d83ca39760ec0a01128c0dade1
T +closed 7694b9bc3003db6ba0b41c5029c8f7b84c07724e7a518e835e98b3c46e4ea227
U drh U drh
Z e0b06ff9de331820a7420ba45b53f562 Z 3fc014f602248e5c82ae5fe3e9828c74

View File

@@ -1 +1 @@
defa0515b8fd50ed9be699542f8c6695dd4a60c02f310665db6657ec5b6b67d0 3e9f1635271c92dce5324728b4ee1cc1a1856ec3c60b1b512a652c21e010e63e

View File

@@ -136,12 +136,10 @@
#define SQLITE_FSFLAGS_IS_MSDOS 0x1 #define SQLITE_FSFLAGS_IS_MSDOS 0x1
/* /*
** If we are to be thread-safe, include the pthreads header and define ** If we are to be thread-safe, include the pthreads header.
** the SQLITE_UNIX_THREADS macro.
*/ */
#if SQLITE_THREADSAFE #if SQLITE_THREADSAFE
# include <pthread.h> # include <pthread.h>
# define SQLITE_UNIX_THREADS 1
#endif #endif
/* /*
@@ -1119,8 +1117,7 @@ struct unixFileId {
/* /*
** An instance of the following structure is allocated for each open ** An instance of the following structure is allocated for each open
** inode. Or, on LinuxThreads, there is one of these structures for ** inode.
** each inode opened by each thread.
** **
** A single inode can have multiple file descriptors, so each unixFile ** A single inode can have multiple file descriptors, so each unixFile
** structure contains a pointer to an instance of this object and this ** structure contains a pointer to an instance of this object and this
@@ -1166,13 +1163,16 @@ struct unixInodeInfo {
/* /*
** A lists of all unixInodeInfo objects. ** A lists of all unixInodeInfo objects.
**
** Must hold unixBigLock in order to read or write this variable.
*/ */
static unixInodeInfo *inodeList = 0; /* All unixInodeInfo objects */ static unixInodeInfo *inodeList = 0; /* All unixInodeInfo objects */
#ifdef SQLITE_DEBUG #ifdef SQLITE_DEBUG
/* /*
** True if the inode mutex is held, or not. Used only within assert() ** True if the inode mutex (on the unixFile.pFileMutex field) is held, or not.
** to help verify correct mutex usage. ** This routine is used only within assert() to help verify correct mutex
** usage.
*/ */
int unixFileMutexHeld(unixFile *pFile){ int unixFileMutexHeld(unixFile *pFile){
assert( pFile->pInode ); assert( pFile->pInode );
@@ -1300,8 +1300,8 @@ static void closePendingFds(unixFile *pFile){
/* /*
** Release a unixInodeInfo structure previously allocated by findInodeInfo(). ** Release a unixInodeInfo structure previously allocated by findInodeInfo().
** **
** The mutex entered using the unixEnterMutex() function must be held ** The global mutex must be held when this routine is called, but the mutex
** when this function is called. ** on the inode being deleted must NOT be held.
*/ */
static void releaseInodeInfo(unixFile *pFile){ static void releaseInodeInfo(unixFile *pFile){
unixInodeInfo *pInode = pFile->pInode; unixInodeInfo *pInode = pFile->pInode;
@@ -1336,8 +1336,7 @@ static void releaseInodeInfo(unixFile *pFile){
** describes that file descriptor. Create a new one if necessary. The ** describes that file descriptor. Create a new one if necessary. The
** return value might be uninitialized if an error occurs. ** return value might be uninitialized if an error occurs.
** **
** The mutex entered using the unixEnterMutex() function must be held ** The global mutex must held when calling this routine.
** when this function is called.
** **
** Return an appropriate error code. ** Return an appropriate error code.
*/ */
@@ -1398,6 +1397,7 @@ static int findInodeInfo(
#else #else
fileId.ino = (u64)statbuf.st_ino; fileId.ino = (u64)statbuf.st_ino;
#endif #endif
assert( unixMutexHeld() );
pInode = inodeList; pInode = inodeList;
while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){ while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){
pInode = pInode->pNext; pInode = pInode->pNext;
@@ -1417,6 +1417,7 @@ static int findInodeInfo(
} }
} }
pInode->nRef = 1; pInode->nRef = 1;
assert( unixMutexHeld() );
pInode->pNext = inodeList; pInode->pNext = inodeList;
pInode->pPrev = 0; pInode->pPrev = 0;
if( inodeList ) inodeList->pPrev = pInode; if( inodeList ) inodeList->pPrev = pInode;
@@ -4223,7 +4224,7 @@ static int unixGetpagesize(void){
*/ */
struct unixShmNode { struct unixShmNode {
unixInodeInfo *pInode; /* unixInodeInfo that owns this SHM node */ unixInodeInfo *pInode; /* unixInodeInfo that owns this SHM node */
sqlite3_mutex *mutex; /* Mutex to access this object */ sqlite3_mutex *pShmMutex; /* Mutex to access this object */
char *zFilename; /* Name of the mmapped file */ char *zFilename; /* Name of the mmapped file */
int h; /* Open file descriptor */ int h; /* Open file descriptor */
int szRegion; /* Size of shared-memory regions */ int szRegion; /* Size of shared-memory regions */
@@ -4247,16 +4248,16 @@ struct unixShmNode {
** The following fields are initialized when this object is created and ** The following fields are initialized when this object is created and
** are read-only thereafter: ** are read-only thereafter:
** **
** unixShm.pFile ** unixShm.pShmNode
** unixShm.id ** unixShm.id
** **
** All other fields are read/write. The unixShm.pFile->mutex must be held ** All other fields are read/write. The unixShm.pShmNode->pShmMutex must
** while accessing any read/write fields. ** be held while accessing any read/write fields.
*/ */
struct unixShm { struct unixShm {
unixShmNode *pShmNode; /* The underlying unixShmNode object */ unixShmNode *pShmNode; /* The underlying unixShmNode object */
unixShm *pNext; /* Next unixShm with the same unixShmNode */ unixShm *pNext; /* Next unixShm with the same unixShmNode */
u8 hasMutex; /* True if holding the unixShmNode mutex */ u8 hasMutex; /* True if holding the unixShmNode->pShmMutex */
u8 id; /* Id of this connection within its unixShmNode */ u8 id; /* Id of this connection within its unixShmNode */
u16 sharedMask; /* Mask of shared locks held */ u16 sharedMask; /* Mask of shared locks held */
u16 exclMask; /* Mask of exclusive locks held */ u16 exclMask; /* Mask of exclusive locks held */
@@ -4286,7 +4287,7 @@ static int unixShmSystemLock(
/* Access to the unixShmNode object is serialized by the caller */ /* Access to the unixShmNode object is serialized by the caller */
pShmNode = pFile->pInode->pShmNode; pShmNode = pFile->pInode->pShmNode;
assert( pShmNode->nRef==0 || sqlite3_mutex_held(pShmNode->mutex) ); assert( pShmNode->nRef==0 || sqlite3_mutex_held(pShmNode->pShmMutex) );
/* Shared locks never span more than one byte */ /* Shared locks never span more than one byte */
assert( n==1 || lockType!=F_RDLCK ); assert( n==1 || lockType!=F_RDLCK );
@@ -4372,7 +4373,7 @@ static void unixShmPurge(unixFile *pFd){
int nShmPerMap = unixShmRegionPerMap(); int nShmPerMap = unixShmRegionPerMap();
int i; int i;
assert( p->pInode==pFd->pInode ); assert( p->pInode==pFd->pInode );
sqlite3_mutex_free(p->mutex); sqlite3_mutex_free(p->pShmMutex);
for(i=0; i<p->nRegion; i+=nShmPerMap){ for(i=0; i<p->nRegion; i+=nShmPerMap){
if( p->h>=0 ){ if( p->h>=0 ){
osMunmap(p->apRegion[i], p->szRegion); osMunmap(p->apRegion[i], p->szRegion);
@@ -4543,8 +4544,8 @@ static int unixOpenSharedMemory(unixFile *pDbFd){
pDbFd->pInode->pShmNode = pShmNode; pDbFd->pInode->pShmNode = pShmNode;
pShmNode->pInode = pDbFd->pInode; pShmNode->pInode = pDbFd->pInode;
if( sqlite3GlobalConfig.bCoreMutex ){ if( sqlite3GlobalConfig.bCoreMutex ){
pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); pShmNode->pShmMutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
if( pShmNode->mutex==0 ){ if( pShmNode->pShmMutex==0 ){
rc = SQLITE_NOMEM_BKPT; rc = SQLITE_NOMEM_BKPT;
goto shm_open_err; goto shm_open_err;
} }
@@ -4587,13 +4588,13 @@ static int unixOpenSharedMemory(unixFile *pDbFd){
** the cover of the unixEnterMutex() mutex and the pointer from the ** the cover of the unixEnterMutex() mutex and the pointer from the
** new (struct unixShm) object to the pShmNode has been set. All that is ** new (struct unixShm) object to the pShmNode has been set. All that is
** left to do is to link the new object into the linked list starting ** left to do is to link the new object into the linked list starting
** at pShmNode->pFirst. This must be done while holding the pShmNode->mutex ** at pShmNode->pFirst. This must be done while holding the
** mutex. ** pShmNode->pShmMutex.
*/ */
sqlite3_mutex_enter(pShmNode->mutex); sqlite3_mutex_enter(pShmNode->pShmMutex);
p->pNext = pShmNode->pFirst; p->pNext = pShmNode->pFirst;
pShmNode->pFirst = p; pShmNode->pFirst = p;
sqlite3_mutex_leave(pShmNode->mutex); sqlite3_mutex_leave(pShmNode->pShmMutex);
return rc; return rc;
/* Jump here on any error */ /* Jump here on any error */
@@ -4645,7 +4646,7 @@ static int unixShmMap(
p = pDbFd->pShm; p = pDbFd->pShm;
pShmNode = p->pShmNode; pShmNode = p->pShmNode;
sqlite3_mutex_enter(pShmNode->mutex); sqlite3_mutex_enter(pShmNode->pShmMutex);
if( pShmNode->isUnlocked ){ if( pShmNode->isUnlocked ){
rc = unixLockSharedMemory(pDbFd, pShmNode); rc = unixLockSharedMemory(pDbFd, pShmNode);
if( rc!=SQLITE_OK ) goto shmpage_out; if( rc!=SQLITE_OK ) goto shmpage_out;
@@ -4754,7 +4755,7 @@ shmpage_out:
*pp = 0; *pp = 0;
} }
if( pShmNode->isReadonly && rc==SQLITE_OK ) rc = SQLITE_READONLY; if( pShmNode->isReadonly && rc==SQLITE_OK ) rc = SQLITE_READONLY;
sqlite3_mutex_leave(pShmNode->mutex); sqlite3_mutex_leave(pShmNode->pShmMutex);
return rc; return rc;
} }
@@ -4793,7 +4794,7 @@ static int unixShmLock(
mask = (1<<(ofst+n)) - (1<<ofst); mask = (1<<(ofst+n)) - (1<<ofst);
assert( n>1 || mask==(1<<ofst) ); assert( n>1 || mask==(1<<ofst) );
sqlite3_mutex_enter(pShmNode->mutex); sqlite3_mutex_enter(pShmNode->pShmMutex);
if( flags & SQLITE_SHM_UNLOCK ){ if( flags & SQLITE_SHM_UNLOCK ){
u16 allMask = 0; /* Mask of locks held by siblings */ u16 allMask = 0; /* Mask of locks held by siblings */
@@ -4866,7 +4867,7 @@ static int unixShmLock(
} }
} }
} }
sqlite3_mutex_leave(pShmNode->mutex); sqlite3_mutex_leave(pShmNode->pShmMutex);
OSTRACE(("SHM-LOCK shmid-%d, pid-%d got %03x,%03x\n", OSTRACE(("SHM-LOCK shmid-%d, pid-%d got %03x,%03x\n",
p->id, osGetpid(0), p->sharedMask, p->exclMask)); p->id, osGetpid(0), p->sharedMask, p->exclMask));
return rc; return rc;
@@ -4916,14 +4917,14 @@ static int unixShmUnmap(
/* Remove connection p from the set of connections associated /* Remove connection p from the set of connections associated
** with pShmNode */ ** with pShmNode */
sqlite3_mutex_enter(pShmNode->mutex); sqlite3_mutex_enter(pShmNode->pShmMutex);
for(pp=&pShmNode->pFirst; (*pp)!=p; pp = &(*pp)->pNext){} for(pp=&pShmNode->pFirst; (*pp)!=p; pp = &(*pp)->pNext){}
*pp = p->pNext; *pp = p->pNext;
/* Free the connection p */ /* Free the connection p */
sqlite3_free(p); sqlite3_free(p);
pDbFd->pShm = 0; pDbFd->pShm = 0;
sqlite3_mutex_leave(pShmNode->mutex); sqlite3_mutex_leave(pShmNode->pShmMutex);
/* If pShmNode->nRef has reached 0, then close the underlying /* If pShmNode->nRef has reached 0, then close the underlying
** shared-memory file, too */ ** shared-memory file, too */