From 8f6ba1fc5b05919c0414a02a98ed2bfa958d2901 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 28 Mar 2022 02:40:55 +0000 Subject: [PATCH] more TDB --- source/libs/tdb/src/db/tdbPCache.c | 28 ++++++++++++++-------------- source/libs/tdb/src/db/tdbPager.c | 2 +- source/libs/tdb/src/inc/tdbOs.h | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/source/libs/tdb/src/db/tdbPCache.c b/source/libs/tdb/src/db/tdbPCache.c index 1e93d87ab8..981dd63593 100644 --- a/source/libs/tdb/src/db/tdbPCache.c +++ b/source/libs/tdb/src/db/tdbPCache.c @@ -15,16 +15,16 @@ #include "tdbInt.h" struct SPCache { - int pageSize; - int cacheSize; - pthread_mutex_t mutex; - int nFree; - SPage *pFree; - int nPage; - int nHash; - SPage **pgHash; - int nRecyclable; - SPage lru; + int pageSize; + int cacheSize; + tdb_mutex_t mutex; + int nFree; + SPage *pFree; + int nPage; + int nHash; + SPage **pgHash; + int nRecyclable; + SPage lru; }; #define PCACHE_PAGE_HASH(pPgid) \ @@ -116,13 +116,13 @@ void tdbPCacheRelease(SPCache *pCache, SPage *pPage) { } } -static void tdbPCacheInitLock(SPCache *pCache) { pthread_mutex_init(&(pCache->mutex), NULL); } +static void tdbPCacheInitLock(SPCache *pCache) { tdbMutexInit(&(pCache->mutex), NULL); } -static void tdbPCacheClearLock(SPCache *pCache) { pthread_mutex_destroy(&(pCache->mutex)); } +static void tdbPCacheClearLock(SPCache *pCache) { tdbMutexDestroy(&(pCache->mutex)); } -static void tdbPCacheLock(SPCache *pCache) { pthread_mutex_lock(&(pCache->mutex)); } +static void tdbPCacheLock(SPCache *pCache) { tdbMutexLock(&(pCache->mutex)); } -static void tdbPCacheUnlock(SPCache *pCache) { pthread_mutex_unlock(&(pCache->mutex)); } +static void tdbPCacheUnlock(SPCache *pCache) { tdbMutexDestroy(&(pCache->mutex)); } static bool tdbPCacheLocked(SPCache *pCache) { assert(0); diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c index db2568c5aa..5f79d60a78 100644 --- a/source/libs/tdb/src/db/tdbPager.c +++ b/source/libs/tdb/src/db/tdbPager.c @@ -206,7 +206,7 @@ int tdbPagerCommit(SPager *pPager) { // TODO: release the page } - fsync(pPager->fd); + tdbOsFSync(pPager->fd); tdbOsClose(pPager->jfd); remove(pPager->jFileName); diff --git a/source/libs/tdb/src/inc/tdbOs.h b/source/libs/tdb/src/inc/tdbOs.h index b05ce47ac5..0d7a3299f1 100644 --- a/source/libs/tdb/src/inc/tdbOs.h +++ b/source/libs/tdb/src/inc/tdbOs.h @@ -45,12 +45,14 @@ typedef TdFilePtr tdb_fd_t; #define tdbOsRead taosReadFile #define tdbOsPRead taosPReadFile #define tdbOsWrite taosWriteFile +#define tdbOsFSync taosFsyncFile #else #define tdbOsOpen open #define tdbOsClose close #define tdbOsRead read #define tdbOsPRead pread #define tdbOsWrite write +#define tdbOsFSync fsync #endif // For threads and lock @@ -65,6 +67,14 @@ typedef TdThreadSpinlock tdb_spinlock_t; #define tdbSpinlockUnlock taosThreadSpinUnlock #define tdbSpinlockTrylock +// mutex lock +typedef TdThreadMutex tdb_mutex_t; + +#define tdbMutexInit taosThreadMutexInit +#define tdbMutexDestroy taosThreadMutexDestroy +#define tdbMutexLock taosThreadMutexLock +#define tdbMutexUnlock taosThreadMutexUnlock + #else // spin lock @@ -76,6 +86,14 @@ typedef pthread_spinlock_t tdb_spinlock_t; #define tdbSpinlockUnlock pthread_spin_unlock #define tdbSpinlockTrylock pthread_spin_trylock +// mutex lock +typedef pthread_mutex_t tdb_mutex_t; + +#define tdbMutexInit pthread_mutex_init +#define tdbMutexDestroy pthread_mutex_destroy +#define tdbMutexLock pthread_mutex_lock +#define tdbMutexUnlock pthread_mutex_unlock + #endif #ifdef __cplusplus