Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9d5e0d53
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
9d5e0d53
编写于
12月 17, 2021
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor list
上级
50749639
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
74 addition
and
137 deletion
+74
-137
include/util/tlist.h
include/util/tlist.h
+22
-24
source/dnode/vnode/impl/src/vnodeArenaMAImpl.c
source/dnode/vnode/impl/src/vnodeArenaMAImpl.c
+5
-5
source/dnode/vnode/impl/src/vnodeBufferPool.c
source/dnode/vnode/impl/src/vnodeBufferPool.c
+11
-11
source/dnode/vnode/impl/src/vnodeMgr.c
source/dnode/vnode/impl/src/vnodeMgr.c
+3
-3
source/dnode/vnode/tsdb/src/tsdbMemTable.c
source/dnode/vnode/tsdb/src/tsdbMemTable.c
+2
-2
source/util/src/tlist.c
source/util/src/tlist.c
+31
-92
未找到文件。
include/util/tlist.h
浏览文件 @
9d5e0d53
...
...
@@ -19,7 +19,7 @@
extern
"C"
{
#endif
// Single linked list
// Single linked list
================
#define TD_SLIST_NODE(TYPE) \
struct { \
struct TYPE *sl_next_; \
...
...
@@ -35,30 +35,30 @@ extern "C" {
#define TD_SLIST_NELES(sl) ((sl)->sl_neles_)
#define TD_SLIST_NODE_NEXT(sln) ((sln)->sl_next_)
#define
tSListInit(sl)
\
#define
TD_SLIST_INIT(sl)
\
do { \
(sl)->sl_head_ = NULL; \
(sl)->sl_neles_ = 0; \
} while (0)
#define
tSListPush(sl, sln)
\
#define
TD_SLIST_PUSH(sl, sln)
\
do { \
TD_SLIST_NODE_NEXT(sln) = TD_SLIST_HEAD(sl); \
TD_SLIST_HEAD(sl) = (sln); \
TD_SLIST_NELES(sl) += 1; \
} while (0)
#define
tSListPop(sl)
\
#define
TD_SLIST_POP(sl)
\
do { \
TD_SLIST_HEAD(sl) = TD_SLIST_NODE_NEXT(TD_SLIST_HEAD(sl)); \
TD_SLIST_NELES(sl) -= 1; \
} while (0)
// Double linked list
// Double linked list
================
#define TD_DLIST_NODE(TYPE) \
struct { \
struct TYPE *dl_prev_;
\
struct TYPE *dl_next_;
\
struct TYPE *dl_prev_; \
struct TYPE *dl_next_; \
}
#define TD_DLIST(TYPE) \
...
...
@@ -74,13 +74,13 @@ extern "C" {
#define TD_DLIST_TAIL(dl) ((dl)->dl_tail_)
#define TD_DLIST_NELES(dl) ((dl)->dl_neles_)
#define
tDListInit(dl)
\
#define
TD_DLIST_INIT(dl)
\
do { \
TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = NULL; \
TD_DLIST_NELES(dl) = 0; \
} while (0)
#define
tDListAppend(dl, dln)
\
#define
TD_DLIST_APPEND(dl, dln)
\
do { \
if (TD_DLIST_HEAD(dl) == NULL) { \
TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \
...
...
@@ -94,7 +94,7 @@ extern "C" {
TD_DLIST_NELES(dl) += 1; \
} while (0)
#define
tDListPrepend(dl, dln)
\
#define
TD_DLIST_PREPEND(dl, dln)
\
do { \
if (TD_DLIST_HEAD(dl) == NULL) { \
TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \
...
...
@@ -108,7 +108,7 @@ extern "C" {
TD_DLIST_NELES(dl) += 1; \
} while (0)
#define
tDListPop(dl, dln)
\
#define
TD_DLIST_POP(dl, dln)
\
do { \
if (TD_DLIST_HEAD(dl) == (dln)) { \
TD_DLIST_HEAD(dl) = TD_DLIST_NODE_NEXT(dln); \
...
...
@@ -126,19 +126,17 @@ extern "C" {
TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \
} while (0)
// General double linked list
typedef
enum
{
TD_LIST_FORWARD
,
TD_LIST_BACKWARD
}
TD_LIST_DIRECTION_T
;
typedef
struct
_list_node
{
struct
_list_node
*
next
;
struct
_list_node
*
prev
;
char
data
[];
typedef
struct
SListNode
{
TD_DLIST_NODE
(
SListNode
);
char
data
[];
}
SListNode
;
typedef
struct
{
struct
_list_node
*
head
;
struct
_list_node
*
tail
;
int
numOfEles
;
int
eleSize
;
TD_DLIST
(
SListNode
);
int
eleSize
;
}
SList
;
typedef
struct
{
...
...
@@ -146,11 +144,11 @@ typedef struct {
TD_LIST_DIRECTION_T
direction
;
}
SListIter
;
#define listHead(l)
(l)->head
#define listTail(l)
(l)->tail
#define listNEles(l)
(l)->numOfEles
#define listEleSize(l) (
l)->eleSize
#define isListEmpty(l) (
(l)->numOfEles
== 0)
#define listHead(l)
TD_DLIST_HEAD(l)
#define listTail(l)
TD_DLIST_TAIL(l)
#define listNEles(l)
TD_DLIST_NELES(l)
#define listEleSize(l) (
(l)->eleSize)
#define isListEmpty(l) (
TD_DLIST_NELES(l)
== 0)
#define listNodeFree(n) free(n)
void
tdListInit
(
SList
*
list
,
int
eleSize
);
...
...
source/dnode/vnode/impl/src/vnodeArenaMAImpl.c
浏览文件 @
9d5e0d53
...
...
@@ -27,7 +27,7 @@ SVMemAllocator *vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize) {
pVMA
->
capacity
=
capacity
;
pVMA
->
ssize
=
ssize
;
pVMA
->
lsize
=
lsize
;
tSListInit
(
&
(
pVMA
->
nlist
));
TD_SLIST_INIT
(
&
(
pVMA
->
nlist
));
pVMA
->
pNode
=
vArenaNodeNew
(
capacity
);
if
(
pVMA
->
pNode
==
NULL
)
{
...
...
@@ -35,7 +35,7 @@ SVMemAllocator *vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize) {
return
NULL
;
}
tSListPush
(
&
(
pVMA
->
nlist
),
pVMA
->
pNode
);
TD_SLIST_PUSH
(
&
(
pVMA
->
nlist
),
pVMA
->
pNode
);
return
pVMA
;
}
...
...
@@ -44,7 +44,7 @@ void vmaDestroy(SVMemAllocator *pVMA) {
if
(
pVMA
)
{
while
(
TD_SLIST_NELES
(
&
(
pVMA
->
nlist
))
>
1
)
{
SVArenaNode
*
pNode
=
TD_SLIST_HEAD
(
&
(
pVMA
->
nlist
));
tSListPop
(
&
(
pVMA
->
nlist
));
TD_SLIST_POP
(
&
(
pVMA
->
nlist
));
vArenaNodeFree
(
pNode
);
}
...
...
@@ -55,7 +55,7 @@ void vmaDestroy(SVMemAllocator *pVMA) {
void
vmaReset
(
SVMemAllocator
*
pVMA
)
{
while
(
TD_SLIST_NELES
(
&
(
pVMA
->
nlist
))
>
1
)
{
SVArenaNode
*
pNode
=
TD_SLIST_HEAD
(
&
(
pVMA
->
nlist
));
tSListPop
(
&
(
pVMA
->
nlist
));
TD_SLIST_POP
(
&
(
pVMA
->
nlist
));
vArenaNodeFree
(
pNode
);
}
...
...
@@ -75,7 +75,7 @@ void *vmaMalloc(SVMemAllocator *pVMA, uint64_t size) {
return
NULL
;
}
tSListPush
(
&
(
pVMA
->
nlist
),
pNode
);
TD_SLIST_PUSH
(
&
(
pVMA
->
nlist
),
pNode
);
}
ptr
=
pNode
->
ptr
;
...
...
source/dnode/vnode/impl/src/vnodeBufferPool.c
浏览文件 @
9d5e0d53
...
...
@@ -39,8 +39,8 @@ int vnodeOpenBufPool(SVnode *pVnode) {
return
-
1
;
}
tDListInit
(
&
(
pVnode
->
pBufPool
->
free
));
tDListInit
(
&
(
pVnode
->
pBufPool
->
incycle
));
TD_DLIST_INIT
(
&
(
pVnode
->
pBufPool
->
free
));
TD_DLIST_INIT
(
&
(
pVnode
->
pBufPool
->
incycle
));
pVnode
->
pBufPool
->
inuse
=
NULL
;
...
...
@@ -54,7 +54,7 @@ int vnodeOpenBufPool(SVnode *pVnode) {
return
-
1
;
}
tDListAppend
(
&
(
pVnode
->
pBufPool
->
free
),
pVMA
);
TD_DLIST_APPEND
(
&
(
pVnode
->
pBufPool
->
free
),
pVMA
);
}
pVnode
->
pBufPool
->
pMAF
=
(
SMemAllocatorFactory
*
)
malloc
(
sizeof
(
SMemAllocatorFactory
));
...
...
@@ -76,14 +76,14 @@ void vnodeCloseBufPool(SVnode *pVnode) {
while
(
true
)
{
SVMemAllocator
*
pVMA
=
TD_DLIST_HEAD
(
&
(
pVnode
->
pBufPool
->
incycle
));
if
(
pVMA
==
NULL
)
break
;
tDListPop
(
&
(
pVnode
->
pBufPool
->
incycle
),
pVMA
);
TD_DLIST_POP
(
&
(
pVnode
->
pBufPool
->
incycle
),
pVMA
);
vmaDestroy
(
pVMA
);
}
while
(
true
)
{
SVMemAllocator
*
pVMA
=
TD_DLIST_HEAD
(
&
(
pVnode
->
pBufPool
->
free
));
if
(
pVMA
==
NULL
)
break
;
tDListPop
(
&
(
pVnode
->
pBufPool
->
free
),
pVMA
);
TD_DLIST_POP
(
&
(
pVnode
->
pBufPool
->
free
),
pVMA
);
vmaDestroy
(
pVMA
);
}
...
...
@@ -97,7 +97,7 @@ int vnodeBufPoolSwitch(SVnode *pVnode) {
pVnode
->
pBufPool
->
inuse
=
NULL
;
tDListAppend
(
&
(
pVnode
->
pBufPool
->
incycle
),
pvma
);
TD_DLIST_APPEND
(
&
(
pVnode
->
pBufPool
->
incycle
),
pvma
);
return
0
;
}
...
...
@@ -106,9 +106,9 @@ int vnodeBufPoolRecycle(SVnode *pVnode) {
SVMemAllocator
*
pvma
=
TD_DLIST_HEAD
(
&
(
pBufPool
->
incycle
));
ASSERT
(
pvma
!=
NULL
);
tDListPop
(
&
(
pBufPool
->
incycle
),
pvma
);
TD_DLIST_POP
(
&
(
pBufPool
->
incycle
),
pvma
);
vmaReset
(
pvma
);
tDListAppend
(
&
(
pBufPool
->
free
),
pvma
);
TD_DLIST_APPEND
(
&
(
pBufPool
->
free
),
pvma
);
return
0
;
}
...
...
@@ -121,7 +121,7 @@ void *vnodeMalloc(SVnode *pVnode, uint64_t size) {
// TODO: add sem_wait and sem_post
pBufPool
->
inuse
=
TD_DLIST_HEAD
(
&
(
pBufPool
->
free
));
if
(
pBufPool
->
inuse
)
{
tDListPop
(
&
(
pBufPool
->
free
),
pBufPool
->
inuse
);
TD_DLIST_POP
(
&
(
pBufPool
->
free
),
pBufPool
->
inuse
);
break
;
}
else
{
// tsem_wait(&(pBufPool->hasFree));
...
...
@@ -184,7 +184,7 @@ static void vBufPoolDestroyMA(SMemAllocatorFactory *pMAF, SMemAllocator *pMA) {
free
(
pMA
);
if
(
--
pVMA
->
_ref
.
val
==
0
)
{
tDListPop
(
&
(
pVnode
->
pBufPool
->
incycle
),
pVMA
);
tDListAppend
(
&
(
pVnode
->
pBufPool
->
free
),
pVMA
);
TD_DLIST_POP
(
&
(
pVnode
->
pBufPool
->
incycle
),
pVMA
);
TD_DLIST_APPEND
(
&
(
pVnode
->
pBufPool
->
free
),
pVMA
);
}
}
\ No newline at end of file
source/dnode/vnode/impl/src/vnodeMgr.c
浏览文件 @
9d5e0d53
...
...
@@ -34,7 +34,7 @@ int vnodeInit(uint16_t nthreads) {
pthread_mutex_init
(
&
(
vnodeMgr
.
mutex
),
NULL
);
pthread_cond_init
(
&
(
vnodeMgr
.
hasTask
),
NULL
);
tDListInit
(
&
(
vnodeMgr
.
queue
));
TD_DLIST_INIT
(
&
(
vnodeMgr
.
queue
));
for
(
uint16_t
i
=
0
;
i
<
nthreads
;
i
++
)
{
pthread_create
(
&
(
vnodeMgr
.
threads
[
i
]),
NULL
,
loop
,
NULL
);
...
...
@@ -77,7 +77,7 @@ void vnodeClear() {
int
vnodeScheduleTask
(
SVnodeTask
*
pTask
)
{
pthread_mutex_lock
(
&
(
vnodeMgr
.
mutex
));
tDListAppend
(
&
(
vnodeMgr
.
queue
),
pTask
);
TD_DLIST_APPEND
(
&
(
vnodeMgr
.
queue
),
pTask
);
pthread_cond_signal
(
&
(
vnodeMgr
.
hasTask
));
...
...
@@ -101,7 +101,7 @@ static void* loop(void* arg) {
pthread_cond_wait
(
&
(
vnodeMgr
.
hasTask
),
&
(
vnodeMgr
.
mutex
));
}
}
else
{
tDListPop
(
&
(
vnodeMgr
.
queue
),
pTask
);
TD_DLIST_POP
(
&
(
vnodeMgr
.
queue
),
pTask
);
break
;
}
}
...
...
source/dnode/vnode/tsdb/src/tsdbMemTable.c
浏览文件 @
9d5e0d53
...
...
@@ -62,7 +62,7 @@ STsdbMemTable *tsdbNewMemTable(SMemAllocatorFactory *pMAF) {
pMemTable
->
keyMax
=
TSKEY_MIN
;
pMemTable
->
nRow
=
0
;
pMemTable
->
pMA
=
pMA
;
tSListInit
(
&
(
pMemTable
->
list
));
TD_SLIST_INIT
(
&
(
pMemTable
->
list
));
// TODO
return
pMemTable
;
...
...
@@ -86,7 +86,7 @@ int tsdbInsertDataToMemTable(STsdbMemTable *pMemTable, SSubmitMsg *pMsg) {
// TODO
}
tSListPush
(
&
(
pMemTable
->
list
),
pTbData
);
TD_SLIST_PUSH
(
&
(
pMemTable
->
list
),
pTbData
);
return
0
;
}
...
...
source/util/src/tlist.c
浏览文件 @
9d5e0d53
...
...
@@ -17,9 +17,8 @@
#include "os.h"
void
tdListInit
(
SList
*
list
,
int
eleSize
)
{
list
->
eleSize
=
eleSize
;
list
->
numOfEles
=
0
;
list
->
head
=
list
->
tail
=
NULL
;
TD_DLIST_INIT
(
list
);
listEleSize
(
list
)
=
eleSize
;
}
SList
*
tdListNew
(
int
eleSize
)
{
...
...
@@ -31,14 +30,11 @@ SList *tdListNew(int eleSize) {
}
void
tdListEmpty
(
SList
*
list
)
{
SListNode
*
node
=
list
->
head
;
while
(
node
)
{
list
->
head
=
node
->
next
;
SListNode
*
node
;
while
(
(
node
=
TD_DLIST_HEAD
(
list
))
!=
NULL
)
{
TD_DLIST_POP
(
list
,
node
)
;
free
(
node
);
node
=
list
->
head
;
}
list
->
head
=
list
->
tail
=
0
;
list
->
numOfEles
=
0
;
}
void
*
tdListFree
(
SList
*
list
)
{
...
...
@@ -50,40 +46,16 @@ void *tdListFree(SList *list) {
return
NULL
;
}
void
tdListPrependNode
(
SList
*
list
,
SListNode
*
node
)
{
if
(
list
->
head
==
NULL
)
{
list
->
head
=
node
;
list
->
tail
=
node
;
}
else
{
node
->
next
=
list
->
head
;
node
->
prev
=
NULL
;
list
->
head
->
prev
=
node
;
list
->
head
=
node
;
}
list
->
numOfEles
++
;
}
void
tdListAppendNode
(
SList
*
list
,
SListNode
*
node
)
{
if
(
list
->
head
==
NULL
)
{
list
->
head
=
node
;
list
->
tail
=
node
;
}
else
{
node
->
prev
=
list
->
tail
;
node
->
next
=
NULL
;
list
->
tail
->
next
=
node
;
list
->
tail
=
node
;
}
void
tdListPrependNode
(
SList
*
list
,
SListNode
*
node
)
{
TD_DLIST_PREPEND
(
list
,
node
);
}
list
->
numOfEles
++
;
}
void
tdListAppendNode
(
SList
*
list
,
SListNode
*
node
)
{
TD_DLIST_APPEND
(
list
,
node
);
}
int
tdListPrepend
(
SList
*
list
,
void
*
data
)
{
SListNode
*
node
=
(
SListNode
*
)
malloc
(
sizeof
(
SListNode
)
+
list
->
eleSize
);
if
(
node
==
NULL
)
return
-
1
;
node
->
next
=
node
->
prev
=
NULL
;
memcpy
((
void
*
)(
node
->
data
),
data
,
list
->
eleSize
);
tdListPrependNode
(
list
,
node
);
TD_DLIST_PREPEND
(
list
,
node
);
return
0
;
}
...
...
@@ -93,73 +65,40 @@ int tdListAppend(SList *list, void *data) {
if
(
node
==
NULL
)
return
-
1
;
memcpy
((
void
*
)(
node
->
data
),
data
,
list
->
eleSize
);
tdListAppendNode
(
list
,
node
);
TD_DLIST_APPEND
(
list
,
node
);
return
0
;
}
SListNode
*
tdListPopHead
(
SList
*
list
)
{
if
(
list
->
head
==
NULL
)
return
NULL
;
SListNode
*
node
=
list
->
head
;
if
(
node
->
next
==
NULL
)
{
list
->
head
=
NULL
;
list
->
tail
=
NULL
;
}
else
{
list
->
head
=
node
->
next
;
SListNode
*
node
;
node
=
TD_DLIST_HEAD
(
list
);
if
(
node
)
{
TD_DLIST_POP
(
list
,
node
);
}
list
->
numOfEles
--
;
node
->
next
=
NULL
;
node
->
prev
=
NULL
;
return
node
;
}
SListNode
*
tdListPopTail
(
SList
*
list
)
{
if
(
list
->
tail
==
NULL
)
return
NULL
;
SListNode
*
node
=
list
->
tail
;
if
(
node
->
prev
==
NULL
)
{
list
->
head
=
NULL
;
list
->
tail
=
NULL
;
}
else
{
list
->
tail
=
node
->
prev
;
}
list
->
numOfEles
--
;
node
->
next
=
node
->
prev
=
NULL
;
return
node
;
}
SListNode
*
node
;
SListNode
*
tdListGetHead
(
SList
*
list
)
{
if
(
list
==
NULL
||
list
->
numOfEles
==
0
)
{
return
NULL
;
node
=
TD_DLIST_TAIL
(
list
);
if
(
node
)
{
TD_DLIST_POP
(
list
,
node
)
;
}
return
list
->
head
;
return
node
;
}
SListNode
*
tsListGetTail
(
SList
*
list
)
{
if
(
list
==
NULL
||
list
->
numOfEles
==
0
)
{
return
NULL
;
}
SListNode
*
tdListGetHead
(
SList
*
list
)
{
return
TD_DLIST_HEAD
(
list
);
}
return
list
->
tail
;
}
SListNode
*
tsListGetTail
(
SList
*
list
)
{
return
TD_DLIST_TAIL
(
list
);
}
SListNode
*
tdListPopNode
(
SList
*
list
,
SListNode
*
node
)
{
if
(
list
->
head
==
node
)
{
list
->
head
=
node
->
next
;
}
if
(
list
->
tail
==
node
)
{
list
->
tail
=
node
->
prev
;
}
if
(
node
->
prev
!=
NULL
)
{
node
->
prev
->
next
=
node
->
next
;
}
if
(
node
->
next
!=
NULL
)
{
node
->
next
->
prev
=
node
->
prev
;
}
list
->
numOfEles
--
;
node
->
next
=
node
->
prev
=
NULL
;
TD_DLIST_POP
(
list
,
node
);
return
node
;
}
...
...
@@ -174,19 +113,19 @@ void tdListMove(SList *src, SList *dst) {
void
tdListDiscard
(
SList
*
list
)
{
if
(
list
)
{
list
->
head
=
list
->
tail
=
NULL
;
list
->
numOfEles
=
0
;
list
Head
(
list
)
=
listTail
(
list
)
=
NULL
;
list
NEles
(
list
)
=
0
;
}
}
void
tdListNodeGetData
(
SList
*
list
,
SListNode
*
node
,
void
*
target
)
{
memcpy
(
target
,
node
->
data
,
list
->
eleSize
);
}
void
tdListNodeGetData
(
SList
*
list
,
SListNode
*
node
,
void
*
target
)
{
memcpy
(
target
,
node
->
data
,
list
EleSize
(
list
)
);
}
void
tdListInitIter
(
SList
*
list
,
SListIter
*
pIter
,
TD_LIST_DIRECTION_T
direction
)
{
pIter
->
direction
=
direction
;
if
(
direction
==
TD_LIST_FORWARD
)
{
pIter
->
next
=
list
->
head
;
pIter
->
next
=
list
Head
(
list
)
;
}
else
{
pIter
->
next
=
list
->
tail
;
pIter
->
next
=
list
Tail
(
list
)
;
}
}
...
...
@@ -194,9 +133,9 @@ SListNode *tdListNext(SListIter *pIter) {
SListNode
*
node
=
pIter
->
next
;
if
(
node
==
NULL
)
return
NULL
;
if
(
pIter
->
direction
==
TD_LIST_FORWARD
)
{
pIter
->
next
=
node
->
next
;
pIter
->
next
=
TD_DLIST_NODE_NEXT
(
node
)
;
}
else
{
pIter
->
next
=
node
->
prev
;
pIter
->
next
=
TD_DLIST_NODE_PREV
(
node
)
;
}
return
node
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录