Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c0e308f2
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c0e308f2
编写于
12月 13, 2021
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more
上级
aaf9ca18
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
109 addition
and
86 deletion
+109
-86
include/util/tdlist.h
include/util/tdlist.h
+90
-68
source/dnode/vnode/impl/src/vnodeArenaMAImpl.c
source/dnode/vnode/impl/src/vnodeArenaMAImpl.c
+12
-11
source/dnode/vnode/impl/src/vnodeBufferPool.c
source/dnode/vnode/impl/src/vnodeBufferPool.c
+7
-7
未找到文件。
include/util/tdlist.h
浏览文件 @
c0e308f2
...
...
@@ -26,87 +26,108 @@ extern "C" {
struct type *sl_next_; \
}
#define TD_SLIST(TYPE) \
struct { \
struct TYPE *sl_head_; \
#define TD_SLIST(TYPE) \
struct { \
struct TYPE *sl_dl_head_; \
int sl_dl_neles_; \
}
#define TD_SLIST_HEAD(sl) ((sl)->sl_head_)
#define TD_SLIST_HEAD(sl) ((sl)->sl_dl_head_)
#define TD_SLIST_NELES(sl) ((sl)->sl_dl_neles_)
#define TD_SLIST_NODE_NEXT(sln) ((sln)->sl_next_)
#define tSListInit(sl) \
do { \
(sl)->sl_head_ = NULL; \
#define tSListInit(sl) \
do { \
(sl)->sl_dl_head_ = NULL; \
(sl)->sl_dl_neles_ = 0; \
} while (0)
#define tSListP
repend(sl, sln)
\
#define tSListP
ush(sl, sln)
\
do { \
TD_SLIST_NODE_NEXT(sln) = TD_SLIST_HEAD(sl); \
TD_SLIST_HEAD(sl) = (sln); \
} while (0);
TD_SLIST_NELES(sl) += 1; \
} while (0)
#define tSListPop(sl) \
do { \
TD_SLIST_HEAD(sl) = TD_SLIST_NODE_NEXT(TD_SLIST_HEAD(sl)); \
TD_SLIST_NELES(sl) -= 1; \
} while (0)
// Double linked list
#define TD_DLIST_NODE(TYPE) \
struct { \
TYPE *
prev_;
\
TYPE *
next_;
\
TYPE *
dl_prev_;
\
TYPE *
dl_next_;
\
}
#define TD_DLIST(TYPE) \
struct { \
TYPE *head_;
\
TYPE *tail_;
\
int
neles_;
\
#define TD_DLIST(TYPE)
\
struct {
\
struct TYPE *dl_head_;
\
struct TYPE *dl_tail_;
\
int
dl_neles_;
\
}
#define tDListInit(l) \
(l)->head_ = (l)->tail_ = NULL; \
(l)->neles_ = 0;
#define TD_DLIST_NODE_PREV(dln) ((dln)->dl_prev_)
#define TD_DLIST_NODE_NEXT(dln) ((dln)->dl_next_)
#define TD_DLIST_HEAD(dl) ((dl)->dl_head_)
#define TD_DLIST_TAIL(dl) ((dl)->dl_tail_)
#define TD_DLIST_NELES(dl) ((dl)->dl_neles_)
#define tlistHead(l) (l)->head_
#define tlistTail(l) (l)->tail_
#define tlistNEles(l) (l)->neles_
#define tDListInit(dl) \
do { \
TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = NULL; \
TD_DLIST_NELES(dl) = 0; \
} while (0)
#define tlistAppend(l, n) \
if ((l)->head_ == NULL) { \
(n)->prev_ = (n)->next_ = NULL; \
(l)->head_ = (l)->tail_ = (n); \
} else { \
(n)->prev_ = (l)->tail_; \
(n)->next_ = NULL; \
(l)->tail_->next_ = (n); \
(l)->tail_ = (n); \
} \
(l)->neles_ += 1;
#define tlistPrepend(l, n) \
if ((l)->head_ == NULL) { \
(n)->prev_ = (n)->next_ = NULL; \
(l)->head_ = (l)->tail_ = (n); \
} else { \
(n)->prev_ = NULL; \
(n)->next_ = (l)->head_; \
(l)->head_->prev_ = (n); \
(l)->head_ = (n); \
} \
(l)->neles_ += 1;
#define tlistPop(l, n) \
if ((l)->head_ == (n)) { \
(l)->head_ = (n)->next_; \
} \
if ((l)->tail_ == (n)) { \
(l)->tail_ = (n)->prev_; \
} \
if ((n)->prev_ != NULL) { \
(n)->prev_->next_ = (n)->next_; \
} \
if ((n)->next_ != NULL) { \
(n)->next_->prev_ = (n)->prev_; \
} \
(l)->neles_ -= 1; \
(n)->prev_ = (n)->next_ = NULL;
#define tDListAppend(dl, dln) \
do { \
if (TD_DLIST_HEAD(dl) == NULL) { \
TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \
TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = (dln); \
} else { \
TD_DLIST_NODE_PREV(dln) = TD_DLIST_TAIL(dl); \
TD_DLIST_NODE_NEXT(dln) = NULL; \
TD_DLIST_NODE_NEXT(TD_DLIST_TAIL(dl)) = (dln); \
TD_DLIST_TAIL(dl) = (dln); \
} \
TD_DLIST_NELES(dl) += 1; \
} while (0)
#define tDListPrepend(dl, dln) \
do { \
if (TD_DLIST_HEAD(dl) == NULL) { \
TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \
TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = (dln); \
} else { \
TD_DLIST_NODE_PREV(dln) = NULL; \
TD_DLIST_NODE_NEXT(dln) = TD_DLIST_HEAD(dl); \
TD_DLIST_NODE_PREV(TD_DLIST_HEAD(dl)) = (dln); \
TD_DLIST_HEAD(dl) = (dln); \
} \
TD_DLIST_NELES(dl) += 1; \
} while (0)
#define tDListPop(dl, dln) \
do { \
if (TD_DLIST_HEAD(dl) == (dln)) { \
TD_DLIST_HEAD(dl) = TD_DLIST_NODE_NEXT(dln); \
} \
if (TD_DLIST_TAIL(dl) == (dln)) { \
TD_DLIST_TAIL(dl) = TD_DLIST_NODE_PREV(dln); \
} \
if (TD_DLIST_NODE_PREV(dln) != NULL) { \
TD_DLIST_NODE_NEXT(TD_DLIST_NODE_PREV(dln)) = TD_DLIST_NODE_NEXT(dln); \
} \
if (TD_DLIST_NODE_NEXT(dln) != NULL) { \
TD_DLIST_NODE_PREV(TD_DLIST_NODE_NEXT(dln)) = TD_DLIST_NODE_PREV(dln); \
} \
TD_DLIST_NELES(dl) -= 1; \
TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \
} while (0)
#if 0
// List iterator
#define TD_LIST_FITER 0
#define TD_LIST_BITER 1
...
...
@@ -118,13 +139,13 @@ extern "C" {
TD_DLIST(S) * it_list_; \
}
#define tlistIterInit(it, l, dir) \
(it)->it_dir_ = (dir); \
(it)->it_list_ = l; \
if ((dir) == TD_LIST_FITER) { \
(it)->it_next_ = (l)->
head_;
\
} else { \
(it)->it_next_ = (l)->
tail_;
\
#define tlistIterInit(it, l, dir)
\
(it)->it_dir_ = (dir);
\
(it)->it_list_ = l;
\
if ((dir) == TD_LIST_FITER) {
\
(it)->it_next_ = (l)->
dl_head_;
\
} else {
\
(it)->it_next_ = (l)->
dl_tail_;
\
}
#define tlistIterNext(it) \
...
...
@@ -139,6 +160,7 @@ extern "C" {
} \
(it)->it_ptr_; \
})
#endif
#ifdef __cplusplus
}
...
...
source/dnode/vnode/impl/src/vnodeArenaMAImpl.c
浏览文件 @
c0e308f2
...
...
@@ -35,7 +35,7 @@ SVMemAllocator *vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize) {
return
NULL
;
}
t
l
istAppend
(
&
(
pVMA
->
nlist
),
pNode
);
t
DL
istAppend
(
&
(
pVMA
->
nlist
),
pNode
);
return
pVMA
;
}
...
...
@@ -43,10 +43,10 @@ SVMemAllocator *vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize) {
void
vmaDestroy
(
SVMemAllocator
*
pVMA
)
{
if
(
pVMA
)
{
while
(
true
)
{
SVArenaNode
*
pNode
=
tlistTail
(
&
(
pVMA
->
nlist
));
SVArenaNode
*
pNode
=
TD_DLIST_TAIL
(
&
(
pVMA
->
nlist
));
if
(
pNode
)
{
t
l
istPop
(
&
(
pVMA
->
nlist
),
pNode
);
t
DL
istPop
(
&
(
pVMA
->
nlist
),
pNode
);
vArenaNodeFree
(
pNode
);
}
else
{
break
;
...
...
@@ -58,18 +58,18 @@ void vmaDestroy(SVMemAllocator *pVMA) {
}
void
vmaReset
(
SVMemAllocator
*
pVMA
)
{
while
(
tlistNEles
(
&
(
pVMA
->
nlist
))
>
1
)
{
SVArenaNode
*
pNode
=
tlistTail
(
&
(
pVMA
->
nlist
));
t
l
istPop
(
&
(
pVMA
->
nlist
),
pNode
);
while
(
TD_DLIST_NELES
(
&
(
pVMA
->
nlist
))
>
1
)
{
SVArenaNode
*
pNode
=
TD_DLIST_TAIL
(
&
(
pVMA
->
nlist
));
t
DL
istPop
(
&
(
pVMA
->
nlist
),
pNode
);
vArenaNodeFree
(
pNode
);
}
SVArenaNode
*
pNode
=
tlistHead
(
&
(
pVMA
->
nlist
));
SVArenaNode
*
pNode
=
TD_DLIST_HEAD
(
&
(
pVMA
->
nlist
));
pNode
->
ptr
=
pNode
->
data
;
}
void
*
vmaMalloc
(
SVMemAllocator
*
pVMA
,
uint64_t
size
)
{
SVArenaNode
*
pNode
=
tlistTail
(
&
(
pVMA
->
nlist
));
SVArenaNode
*
pNode
=
TD_DLIST_TAIL
(
&
(
pVMA
->
nlist
));
void
*
ptr
;
if
(
pNode
->
size
<
POINTER_DISTANCE
(
pNode
->
ptr
,
pNode
->
data
)
+
size
)
{
...
...
@@ -80,7 +80,7 @@ void *vmaMalloc(SVMemAllocator *pVMA, uint64_t size) {
return
NULL
;
}
t
l
istAppend
(
&
(
pVMA
->
nlist
),
pNode
);
t
DL
istAppend
(
&
(
pVMA
->
nlist
),
pNode
);
}
ptr
=
pNode
->
ptr
;
...
...
@@ -94,9 +94,10 @@ void vmaFree(SVMemAllocator *pVMA, void *ptr) {
}
bool
vmaIsFull
(
SVMemAllocator
*
pVMA
)
{
SVArenaNode
*
pNode
=
tlistTail
(
&
(
pVMA
->
nlist
));
SVArenaNode
*
pNode
=
TD_DLIST_TAIL
(
&
(
pVMA
->
nlist
));
return
(
tlistNEles
(
&
(
pVMA
->
nlist
))
>
1
)
||
(
pNode
->
size
<
POINTER_DISTANCE
(
pNode
->
ptr
,
pNode
->
data
)
+
pVMA
->
lsize
);
return
(
TD_DLIST_NELES
(
&
(
pVMA
->
nlist
))
>
1
)
||
(
pNode
->
size
<
POINTER_DISTANCE
(
pNode
->
ptr
,
pNode
->
data
)
+
pVMA
->
lsize
);
}
/* ------------------------ STATIC METHODS ------------------------ */
...
...
source/dnode/vnode/impl/src/vnodeBufferPool.c
浏览文件 @
c0e308f2
...
...
@@ -50,7 +50,7 @@ int vnodeOpenBufPool(SVnode *pVnode) {
return
-
1
;
}
t
l
istAppend
(
&
(
pVnode
->
pBufPool
->
free
),
pVMA
);
t
DL
istAppend
(
&
(
pVnode
->
pBufPool
->
free
),
pVMA
);
}
return
0
;
...
...
@@ -61,16 +61,16 @@ void vnodeCloseBufPool(SVnode *pVnode) {
vmaDestroy
(
pVnode
->
pBufPool
->
inuse
);
while
(
true
)
{
SVMemAllocator
*
pVMA
=
tlistHead
(
&
(
pVnode
->
pBufPool
->
incycle
));
SVMemAllocator
*
pVMA
=
TD_DLIST_HEAD
(
&
(
pVnode
->
pBufPool
->
incycle
));
if
(
pVMA
==
NULL
)
break
;
t
l
istPop
(
&
(
pVnode
->
pBufPool
->
incycle
),
pVMA
);
t
DL
istPop
(
&
(
pVnode
->
pBufPool
->
incycle
),
pVMA
);
vmaDestroy
(
pVMA
);
}
while
(
true
)
{
SVMemAllocator
*
pVMA
=
tlistHead
(
&
(
pVnode
->
pBufPool
->
free
));
SVMemAllocator
*
pVMA
=
TD_DLIST_HEAD
(
&
(
pVnode
->
pBufPool
->
free
));
if
(
pVMA
==
NULL
)
break
;
t
l
istPop
(
&
(
pVnode
->
pBufPool
->
free
),
pVMA
);
t
DL
istPop
(
&
(
pVnode
->
pBufPool
->
free
),
pVMA
);
vmaDestroy
(
pVMA
);
}
...
...
@@ -85,9 +85,9 @@ void *vnodeMalloc(SVnode *pVnode, uint64_t size) {
if
(
pBufPool
->
inuse
==
NULL
)
{
while
(
true
)
{
// TODO: add sem_wait and sem_post
pBufPool
->
inuse
=
tlistHead
(
&
(
pBufPool
->
free
));
pBufPool
->
inuse
=
TD_DLIST_HEAD
(
&
(
pBufPool
->
free
));
if
(
pBufPool
->
inuse
)
{
t
l
istPop
(
&
(
pBufPool
->
free
),
pBufPool
->
inuse
);
t
DL
istPop
(
&
(
pBufPool
->
free
),
pBufPool
->
inuse
);
break
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录