From a195e51c9f5246e6e3ba45891b215a6449a09ae4 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 7 Feb 2022 03:51:02 +0000 Subject: [PATCH] more work --- source/libs/tdb/src/db/pgcache.c | 21 +++++++++++---------- source/libs/tdb/src/inc/pgcache.h | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/source/libs/tdb/src/db/pgcache.c b/source/libs/tdb/src/db/pgcache.c index 5ca65e366e..be26d77f80 100644 --- a/source/libs/tdb/src/db/pgcache.c +++ b/source/libs/tdb/src/db/pgcache.c @@ -22,20 +22,17 @@ struct SPage { typedef TD_DLIST(SPage) SPgList; struct SPgCache { - SPage *pages; - - SPgList freeList; - + SRWLatch mutex; + pgsize_t pgsize; + SPage * pages; + SPgList freeList; struct { - int32_t nbucket; - struct { - SRWLatch latch; - TD_DLIST(SPage) ht; - } * buckets; + int32_t nbucket; + SPgList *buckets; } pght; // page hash table }; -int pgCacheCreate(SPgCache **ppPgCache) { +int pgCacheCreate(SPgCache **ppPgCache, pgsize_t pgsize) { SPgCache *pPgCache; pPgCache = (SPgCache *)calloc(1, sizeof(*pPgCache)); @@ -43,6 +40,10 @@ int pgCacheCreate(SPgCache **ppPgCache) { return -1; } + pPgCache->pgsize = pgsize; + + taosInitRWLatch(&(pPgCache->mutex)); + *ppPgCache = pPgCache; return 0; } diff --git a/source/libs/tdb/src/inc/pgcache.h b/source/libs/tdb/src/inc/pgcache.h index af85e0de63..022198b246 100644 --- a/source/libs/tdb/src/inc/pgcache.h +++ b/source/libs/tdb/src/inc/pgcache.h @@ -24,7 +24,7 @@ typedef struct SPgCache SPgCache; typedef struct SPage SPage; // SPgCache -int pgCacheCreate(SPgCache **ppPgCache); +int pgCacheCreate(SPgCache **ppPgCache, pgsize_t pgsize); int pgCacheDestroy(SPgCache *pPgCache); int pgCacheOpen(SPgCache *pPgCache); int pgCacheClose(SPgCache *pPgCache);