diff options
author | drh <> | 2025-03-05 17:12:42 +0000 |
---|---|---|
committer | drh <> | 2025-03-05 17:12:42 +0000 |
commit | 427e0076a90dead162007d23cb61cf9c2a498d3a (patch) | |
tree | 834450f72c52020d5e6ff141f9f513128510f506 /src | |
parent | 9f19ea83e75893875572f7cb3a1e89ecf4c1841f (diff) | |
download | sqlite-427e0076a90dead162007d23cb61cf9c2a498d3a.tar.gz sqlite-427e0076a90dead162007d23cb61cf9c2a498d3a.zip |
Use AtomicRead() and AtomicWrite() to access the pcache1_g.bUnderPressure
global, to forestall unnecessary angst from thread analyzers.
FossilOrigin-Name: 41ec85637a7fac710a3986ee78ed25a96d331a03653069bae4d9f826cc6f944a
Diffstat (limited to 'src')
-rw-r--r-- | src/pcache1.c | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/pcache1.c b/src/pcache1.c index 88a7b3a0b..39607328f 100644 --- a/src/pcache1.c +++ b/src/pcache1.c @@ -232,10 +232,6 @@ static SQLITE_WSD struct PCacheGlobal { sqlite3_mutex *mutex; /* Mutex for accessing the following: */ PgFreeslot *pFree; /* Free page blocks */ int nFreeSlot; /* Number of unused pcache slots */ - /* The following value requires a mutex to change. We skip the mutex on - ** reading because (1) most platforms read a 32-bit integer atomically and - ** (2) even if an incorrect value is read, no great harm is done since this - ** is really just an optimization. */ int bUnderPressure; /* True if low on PAGECACHE memory */ } pcache1_g; @@ -283,7 +279,7 @@ void sqlite3PCacheBufferSetup(void *pBuf, int sz, int n){ pcache1.nReserve = n>90 ? 10 : (n/10 + 1); pcache1.pStart = pBuf; pcache1.pFree = 0; - pcache1.bUnderPressure = 0; + AtomicStore(&pcache1.bUnderPressure,0); while( n-- ){ p = (PgFreeslot*)pBuf; p->pNext = pcache1.pFree; @@ -351,7 +347,7 @@ static void *pcache1Alloc(int nByte){ if( p ){ pcache1.pFree = pcache1.pFree->pNext; pcache1.nFreeSlot--; - pcache1.bUnderPressure = pcache1.nFreeSlot<pcache1.nReserve; + AtomicStore(&pcache1.bUnderPressure,pcache1.nFreeSlot<pcache1.nReserve); assert( pcache1.nFreeSlot>=0 ); sqlite3StatusHighwater(SQLITE_STATUS_PAGECACHE_SIZE, nByte); sqlite3StatusUp(SQLITE_STATUS_PAGECACHE_USED, 1); @@ -390,7 +386,7 @@ static void pcache1Free(void *p){ pSlot->pNext = pcache1.pFree; pcache1.pFree = pSlot; pcache1.nFreeSlot++; - pcache1.bUnderPressure = pcache1.nFreeSlot<pcache1.nReserve; + AtomicStore(&pcache1.bUnderPressure,pcache1.nFreeSlot<pcache1.nReserve); assert( pcache1.nFreeSlot<=pcache1.nSlot ); sqlite3_mutex_leave(pcache1.mutex); }else{ @@ -521,7 +517,7 @@ void sqlite3PageFree(void *p){ */ static int pcache1UnderMemoryPressure(PCache1 *pCache){ if( pcache1.nSlot && (pCache->szPage+pCache->szExtra)<=pcache1.szSlot ){ - return pcache1.bUnderPressure; + return AtomicLoad(&pcache1.bUnderPressure); }else{ return sqlite3HeapNearlyFull(); } |