From d66cba75e1e4aba185cb69629b6d564fe5bf696e Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 13 Dec 2021 21:06:33 +0800 Subject: [PATCH] more --- include/util/tdlist.h | 49 +++++++++++++------ .../dnode/vnode/impl/inc/vnodeMemAllocator.h | 6 +-- source/dnode/vnode/impl/src/vnodeBufferPool.c | 4 +- 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/include/util/tdlist.h b/include/util/tdlist.h index 0f341801e0..4be1779c74 100644 --- a/include/util/tdlist.h +++ b/include/util/tdlist.h @@ -20,17 +20,36 @@ extern "C" { #endif -#define TD_LIST_NODE(S) \ - struct { \ - S *prev_; \ - S *next_; \ +// Single linked list +#define TD_SLIST_NODE(TYPE) \ + struct { \ + struct type *sl_next_; \ } -#define TD_LIST(S) \ - struct { \ - S * head_; \ - S * tail_; \ - int neles_; \ +#define TD_SLIST(TYPE) \ + struct { \ + struct TYPE *sl_head_; \ + } + +#define TD_SLIST_NODE_NEXT(sln) (sln)->sl_next_ + +#define tSListInit(sl) \ + do { \ + (sl)->sl_head_ = NULL; \ + } while (0) + +// Double linked list +#define TD_DLIST_NODE(S) \ + struct { \ + S *prev_; \ + S *next_; \ + } + +#define TD_DLIST(S) \ + struct { \ + S * head_; \ + S * tail_; \ + int neles_; \ } #define tlistInit(l) \ @@ -84,12 +103,12 @@ extern "C" { // List iterator #define TD_LIST_FITER 0 #define TD_LIST_BITER 1 -#define TD_LIST_ITER(S) \ - struct { \ - int it_dir_; \ - S * it_next_; \ - S * it_ptr_; \ - TD_LIST(S) * it_list_; \ +#define TD_LIST_ITER(S) \ + struct { \ + int it_dir_; \ + S * it_next_; \ + S * it_ptr_; \ + TD_DLIST(S) * it_list_; \ } #define tlistIterInit(it, l, dir) \ diff --git a/source/dnode/vnode/impl/inc/vnodeMemAllocator.h b/source/dnode/vnode/impl/inc/vnodeMemAllocator.h index df8b367d25..6b9fddaa02 100644 --- a/source/dnode/vnode/impl/inc/vnodeMemAllocator.h +++ b/source/dnode/vnode/impl/inc/vnodeMemAllocator.h @@ -26,18 +26,18 @@ typedef struct SVArenaNode SVArenaNode; typedef struct SVMemAllocator SVMemAllocator; struct SVArenaNode { - TD_LIST_NODE(SVArenaNode); + TD_DLIST_NODE(SVArenaNode); uint64_t size; // current node size void * ptr; char data[]; }; struct SVMemAllocator { - TD_LIST_NODE(SVMemAllocator); + TD_DLIST_NODE(SVMemAllocator); uint64_t capacity; uint64_t ssize; uint64_t lsize; - TD_LIST(SVArenaNode) nlist; + TD_DLIST(SVArenaNode) nlist; }; SVMemAllocator *vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize); diff --git a/source/dnode/vnode/impl/src/vnodeBufferPool.c b/source/dnode/vnode/impl/src/vnodeBufferPool.c index d5fcdf91e3..347fe44e26 100644 --- a/source/dnode/vnode/impl/src/vnodeBufferPool.c +++ b/source/dnode/vnode/impl/src/vnodeBufferPool.c @@ -19,8 +19,8 @@ #define VNODE_BUF_POOL_SHARDS 3 struct SVBufPool { - TD_LIST(SVMemAllocator) free; - TD_LIST(SVMemAllocator) incycle; + TD_DLIST(SVMemAllocator) free; + TD_DLIST(SVMemAllocator) incycle; SVMemAllocator *inuse; // MAF for submodules // SMemAllocatorFactory maf;