Try to identify the places in WAL code where thread-safety depends on the

underlying architecture supporting atomic load and store of aligned 32-bit
values.

FossilOrigin-Name: 47d44be4a68d377d0049a12b2587dbbcc0870b469473e1098f7c0358fe8c7532
This commit is contained in:
drh 2018-08-30 20:28:18 +00:00
parent ed9272159e
commit 876c7ea3fa
3 changed files with 23 additions and 11 deletions

View File

@ -1,5 +1,5 @@
C Give\sthe\sdebugging\sroutine\sprint_pager_stats()\sexternal\slinkage\sin\sorder\sto\nsuppress\sharmless\scompiler\sand\sTSAN\swarnings.
D 2018-08-30T18:53:09.671
C Try\sto\sidentify\sthe\splaces\sin\sWAL\scode\swhere\sthread-safety\sdepends\son\sthe\nunderlying\sarchitecture\ssupporting\satomic\sload\sand\sstore\sof\saligned\s32-bit\nvalues.
D 2018-08-30T20:28:18.073
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F Makefile.in d06f463c5b623a61ac27f5cb8214fca9e53a6704d34d6b8f2124e2b1b293c88f
@ -582,7 +582,7 @@ F src/vdbesort.c 90aad5a92608f2dd771c96749beabdb562c9d881131a860a7a5bccf66dc3be7
F src/vdbetrace.c 79d6dbbc479267b255a7de8080eee6e729928a0ef93ed9b0bfa5618875b48392
F src/vtab.c 678992ac8ec677a3f9b08126aaf891441083805e3b42574e3654d44538381c14
F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
F src/wal.c 46bfc9427d527099c17ce00a343a1c3fb8b050b00ddaf90a94398cda44070bf8
F src/wal.c f58ff398f7dba6d6129f27b9a52fc00b46a36d0fea5368706b6d088dde801313
F src/wal.h 606292549f5a7be50b6227bd685fa76e3a4affad71bb8ac5ce4cb5c79f6a176a
F src/walker.c ba7225773931760cf60bf22f34d0cce2588df7ce5ce0f215a52eb88234b55ac4
F src/where.c 155809967fbab889374dedf970ea6561b8fb519fcb165d6ba00776552ecc5cde
@ -1758,7 +1758,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 58078c0d2647a194279fa80e032670441b296ffc3acee692901faa5beca460b7
R a4b705470a4ec2c924173c8c942f70f9
P ff4dc08298ab3988e69fe60802657791f65d2af15f4b1cbd1d02649bc597d0d6
R 8b1c21076160b5400497f5a8fe9f34ce
U drh
Z 1e426c4805f3914010cc98a58db34e64
Z 66336bd926abce6891acc1782fdb9867

View File

@ -1 +1 @@
ff4dc08298ab3988e69fe60802657791f65d2af15f4b1cbd1d02649bc597d0d6
47d44be4a68d377d0049a12b2587dbbcc0870b469473e1098f7c0358fe8c7532

View File

@ -258,6 +258,18 @@ int sqlite3WalTrace = 0;
# define WALTRACE(X)
#endif
/*
** WAL mode depends on atomic aligned 32-bit loads and stores in a few
** places. The following macros try to make this explicit.
*/
#if GCC_VESRION>=5004000
# define AtomicLoad(PTR) __atomic_load_n((PTR),__ATOMIC_RELAXED)
# define AtomicStore(PTR,VAL) __atomic_store_n((PTR),(VAL),__ATOMIC_RELAXED)
#else
# define AtomicLoad(PTR) (*(PTR))
# define AtomicStore(PTR,VAL) (*(PTR) = (VAL))
#endif
/*
** The maximum (and only) versions of the wal and wal-index formats
** that may be interpreted by this version of SQLite.
@ -2555,7 +2567,7 @@ static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int cnt){
}
#endif
for(i=1; i<WAL_NREADER; i++){
u32 thisMark = pInfo->aReadMark[i];
u32 thisMark = AtomicLoad(pInfo->aReadMark+i);
if( mxReadMark<=thisMark && thisMark<=mxFrame ){
assert( thisMark!=READMARK_NOT_USED );
mxReadMark = thisMark;
@ -2568,7 +2580,7 @@ static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int cnt){
for(i=1; i<WAL_NREADER; i++){
rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1);
if( rc==SQLITE_OK ){
mxReadMark = pInfo->aReadMark[i] = mxFrame;
mxReadMark = AtomicStore(pInfo->aReadMark+i,mxFrame);
mxI = i;
walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1);
break;
@ -2620,9 +2632,9 @@ static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int cnt){
** we can guarantee that the checkpointer that set nBackfill could not
** see any pages past pWal->hdr.mxFrame, this problem does not come up.
*/
pWal->minFrame = pInfo->nBackfill+1;
pWal->minFrame = AtomicLoad(&pInfo->nBackfill)+1;
walShmBarrier(pWal);
if( pInfo->aReadMark[mxI]!=mxReadMark
if( AtomicLoad(pInfo->aReadMark+mxI)!=mxReadMark
|| memcmp((void *)walIndexHdr(pWal), &pWal->hdr, sizeof(WalIndexHdr))
){
walUnlockShared(pWal, WAL_READ_LOCK(mxI));