From ed06d82230e4ffd687b26fb3c2384ff53c954e04 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 20 Jan 2022 05:58:38 +0000 Subject: [PATCH] refact --- source/libs/tdb/src/db/tdb_mpool.c | 8 +++---- source/libs/tdb/src/inc/tdb_inc.h | 1 + source/libs/tdb/src/inc/tdb_mpool.h | 33 ++++++++++++++--------------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/source/libs/tdb/src/db/tdb_mpool.c b/source/libs/tdb/src/db/tdb_mpool.c index 0d9ddd9d46..4e005b9e03 100644 --- a/source/libs/tdb/src/db/tdb_mpool.c +++ b/source/libs/tdb/src/db/tdb_mpool.c @@ -18,7 +18,7 @@ int tdbMPoolOpen(TDB_MPOOL **mpp, uint64_t cachesize, pgsize_t pgsize) { TDB_MPOOL *mp; size_t tsize; - MP_PAGE * pagep; + pg_t * pagep; // check parameters if (!TDB_IS_PGSIZE_VLD(pgsize)) { @@ -37,7 +37,7 @@ int tdbMPoolOpen(TDB_MPOOL **mpp, uint64_t cachesize, pgsize_t pgsize) { mp->cachesize = cachesize; mp->pgsize = pgsize; mp->npages = cachesize / pgsize; - mp->pages = (MP_PAGE *)calloc(mp->npages, MP_PAGE_SIZE(pgsize)); + mp->pages = (pg_t *)calloc(mp->npages, MP_PAGE_SIZE(pgsize)); if (mp->pages == NULL) { tdbError("failed to malloc memory pool pages"); free(mp); @@ -47,7 +47,7 @@ int tdbMPoolOpen(TDB_MPOOL **mpp, uint64_t cachesize, pgsize_t pgsize) { TD_DLIST_INIT(&(mp->freeList)); mp->nbucket = mp->npages; - mp->hashtab = (MP_PAGE_LIST *)calloc(mp->nbucket, sizeof(MP_PAGE_LIST)); + mp->hashtab = (pg_list_t *)calloc(mp->nbucket, sizeof(pg_list_t)); if (mp->hashtab == NULL) { tdbError("failed to malloc memory pool hash table"); free(mp->pages); @@ -56,7 +56,7 @@ int tdbMPoolOpen(TDB_MPOOL **mpp, uint64_t cachesize, pgsize_t pgsize) { } for (int i = 0; i < mp->npages; i++) { - pagep = (MP_PAGE *)MP_PAGE_AT(mp, i); + pagep = (pg_t *)MP_PAGE_AT(mp, i); TD_DLIST_APPEND(&mp->freeList, pagep); } diff --git a/source/libs/tdb/src/inc/tdb_inc.h b/source/libs/tdb/src/inc/tdb_inc.h index 82947e2965..ba9d6a560c 100644 --- a/source/libs/tdb/src/inc/tdb_inc.h +++ b/source/libs/tdb/src/inc/tdb_inc.h @@ -18,6 +18,7 @@ #include "os.h" #include "tlist.h" +#include "tlockfree.h" #ifdef __cplusplus extern "C" { diff --git a/source/libs/tdb/src/inc/tdb_mpool.h b/source/libs/tdb/src/inc/tdb_mpool.h index 73596d91dd..6b8cb8f844 100644 --- a/source/libs/tdb/src/inc/tdb_mpool.h +++ b/source/libs/tdb/src/inc/tdb_mpool.h @@ -26,28 +26,27 @@ extern "C" { typedef struct TDB_MPOOL TDB_MPOOL; typedef struct TDB_MPFILE TDB_MPFILE; -typedef struct MP_PAGE { - // SRWLatch rwLatch; - pgid_t mpgid; - uint8_t dirty; - uint8_t fileid[TDB_FILE_UID_LEN]; - int32_t pinRef; - TD_DLIST_NODE(MP_PAGE); +typedef struct pg_t { + SRWLatch rwLatch; + pgid_t mpgid; + uint8_t dirty; + int32_t pinRef; + TD_DLIST_NODE(pg_t); char *page[]; -} MP_PAGE; +} pg_t; -#define MP_PAGE_SIZE(pgsize) (sizeof(MP_PAGE) + (pgsize)) +#define MP_PAGE_SIZE(pgsize) (sizeof(pg_t) + (pgsize)) -typedef TD_DLIST(MP_PAGE) MP_PAGE_LIST; +typedef TD_DLIST(pg_t) pg_list_t; struct TDB_MPOOL { - int64_t cachesize; - pgsize_t pgsize; - int32_t npages; - MP_PAGE * pages; - MP_PAGE_LIST freeList; + int64_t cachesize; + pgsize_t pgsize; + int32_t npages; + pg_t * pages; + pg_list_t freeList; // Hash - int32_t nbucket; - MP_PAGE_LIST *hashtab; + int32_t nbucket; + pg_list_t *hashtab; // TODO: TD_DLIST(TD_MPFILE) mpfList; // MPFILE registered on this memory pool }; -- GitLab