diff --git a/source/libs/tdb/src/db/tdbPCache.c b/source/libs/tdb/src/db/tdbPCache.c index 443e0b4575..262f3d27e6 100644 --- a/source/libs/tdb/src/db/tdbPCache.c +++ b/source/libs/tdb/src/db/tdbPCache.c @@ -21,7 +21,7 @@ struct SPCache { int szPage; int nPages; SPage **aPage; - TdThreadRwlock rwLock; + tdb_mutex_t mutex; int nFree; SPage *pFree; int nPage; @@ -44,11 +44,10 @@ static void tdbPCacheAddPageToHash(SPCache *pCache, SPage *pPage); static void tdbPCacheUnpinPage(SPCache *pCache, SPage *pPage); static int tdbPCacheCloseImpl(SPCache *pCache); -static void tdbPCacheInitLock(SPCache *pCache) { taosThreadRwlockInit(&(pCache->rwLock), NULL); } -static void tdbPCacheDestroyLock(SPCache *pCache) { taosThreadRwlockDestroy(&(pCache->rwLock)); } -static void tdbPCacheRLock(SPCache *pCache) { taosThreadRwlockRdlock(&(pCache->rwLock)); } -static void tdbPCacheWLock(SPCache *pCache) { taosThreadRwlockWrlock(&(pCache->rwLock)); } -static void tdbPCacheUnlock(SPCache *pCache) { taosThreadRwlockUnlock(&(pCache->rwLock)); } +static void tdbPCacheInitLock(SPCache *pCache) { tdbMutexInit(&(pCache->mutex), NULL); } +static void tdbPCacheDestroyLock(SPCache *pCache) { tdbMutexDestroy(&(pCache->mutex)); } +static void tdbPCacheLock(SPCache *pCache) { tdbMutexLock(&(pCache->mutex)); } +static void tdbPCacheUnlock(SPCache *pCache) { tdbMutexUnlock(&(pCache->mutex)); } int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) { SPCache *pCache; @@ -159,7 +158,7 @@ static int tdbPCacheAlterImpl(SPCache *pCache, int32_t nPage) { int tdbPCacheAlter(SPCache *pCache, int32_t nPage) { int ret = 0; - tdbPCacheWLock(pCache); + tdbPCacheLock(pCache); ret = tdbPCacheAlterImpl(pCache, nPage); @@ -172,6 +171,8 @@ SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, TXN *pTxn) { SPage *pPage; i32 nRef = 0; + tdbPCacheLock(pCache); + pPage = tdbPCacheFetchImpl(pCache, pPgid, pTxn); if (pPage) { nRef = tdbRefPage(pPage); @@ -192,7 +193,7 @@ SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, TXN *pTxn) { } void tdbPCacheMarkFree(SPCache *pCache, SPage *pPage) { - tdbPCacheWLock(pCache); + tdbPCacheLock(pCache); tdbPCacheRemovePageFromHash(pCache, pPage); pPage->isFree = 1; tdbPCacheUnlock(pCache); @@ -240,7 +241,7 @@ void tdbPCacheRelease(SPCache *pCache, SPage *pPage, TXN *pTxn) { return; } - tdbPCacheWLock(pCache); + tdbPCacheLock(pCache); nRef = tdbUnrefPage(pPage); tdbTrace("pcache/release page %p/%d/%d/%d", pPage, TDB_PAGE_PGNO(pPage), pPage->id, nRef); if (nRef == 0) { @@ -274,8 +275,6 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, TXN *pTxn) SPage *pPage = NULL; SPage *pPageH = NULL; - tdbPCacheRLock(pCache); - if (!pTxn) { tdbError("tdb/pcache: null ptr pTxn, fetch impl failed."); return NULL; @@ -295,10 +294,6 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, TXN *pTxn) } } - tdbPCacheUnlock(pCache); - - tdbPCacheWLock(pCache); - // 1. pPage == NULL // 2. pPage && pPage->isLocal == 0 && !TDB_TXN_IS_WRITE(pTxn) pPageH = pPage;