This commit is contained in:
Hongze Cheng 2021-12-13 21:06:33 +08:00
parent 2c05341112
commit d66cba75e1
3 changed files with 39 additions and 20 deletions

View File

@ -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) \

View File

@ -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);

View File

@ -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;