Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4383b4d6
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
4383b4d6
编写于
12月 17, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/3.0' into feature/3.0_liaohj
上级
2e68133e
c3bd5d3e
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
202 addition
and
326 deletion
+202
-326
Jenkinsfile
Jenkinsfile
+1
-2
include/util/mallocator.h
include/util/mallocator.h
+20
-15
include/util/tdlist.h
include/util/tdlist.h
+0
-169
include/util/tlist.h
include/util/tlist.h
+118
-13
source/dnode/vnode/impl/inc/vnodeDef.h
source/dnode/vnode/impl/inc/vnodeDef.h
+1
-1
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
+12
-16
source/dnode/vnode/impl/src/vnodeMgr.c
source/dnode/vnode/impl/src/vnodeMgr.c
+3
-3
source/dnode/vnode/tsdb/inc/tsdbDef.h
source/dnode/vnode/tsdb/inc/tsdbDef.h
+1
-1
source/dnode/vnode/tsdb/src/tsdbMemTable.c
source/dnode/vnode/tsdb/src/tsdbMemTable.c
+5
-5
source/util/CMakeLists.txt
source/util/CMakeLists.txt
+2
-3
source/util/src/mallocator.c
source/util/src/mallocator.c
+3
-1
source/util/src/tlist.c
source/util/src/tlist.c
+31
-92
未找到文件。
Jenkinsfile
浏览文件 @
4383b4d6
...
...
@@ -83,8 +83,7 @@ def pre_test(){
mkdir debug
cd debug
cmake .. > /dev/null
make > /dev/null
make install > /dev/null
make -j4> /dev/null
'''
return
1
...
...
include/util/mallocator.h
浏览文件 @
4383b4d6
...
...
@@ -22,23 +22,28 @@
extern
"C"
{
#endif
typedef
struct
SMemAllocator
SMemAllocator
;
typedef
struct
SMemAllocatorFactory
SMemAllocatorFactory
;
struct
SMemAllocator
{
// Memory allocator
#define TD_MEM_ALCT(TYPE) \
struct { \
void *(*malloc_)(struct TYPE *, uint64_t size); \
void (*free_)(struct TYPE *, void *ptr); \
}
#define TD_MA_MALLOC_FUNC(TMA) (TMA)->malloc_
#define TD_MA_FREE_FUNC(TMA) (TMA)->free_
#define TD_MA_MALLOC(TMA, SIZE) (*((TMA)->malloc_))(TMA, (SIZE))
#define TD_MA_FREE(TMA, PTR) (*((TMA)->free_))(TMA, (PTR))
typedef
struct
SMemAllocator
{
void
*
impl
;
void
*
(
*
malloc
)(
SMemAllocator
*
,
uint64_t
size
);
void
*
(
*
calloc
)(
SMemAllocator
*
,
uint64_t
nmemb
,
uint64_t
size
);
void
*
(
*
realloc
)(
SMemAllocator
*
,
void
*
ptr
,
uint64_t
size
);
void
(
*
free
)(
SMemAllocator
*
,
void
*
ptr
);
uint64_t
(
*
usage
)(
SMemAllocator
*
);
};
struct
SMemAllocatorFactory
{
TD_MEM_ALCT
(
SMemAllocator
);
}
SMemAllocator
;
typedef
struct
SMemAllocatorFactory
{
void
*
impl
;
SMemAllocator
*
(
*
create
)(
SMemAllocatorFactory
*
);
void
(
*
destroy
)(
SMemAllocatorFactory
*
,
SMemAllocator
*
);
};
SMemAllocator
*
(
*
create
)(
struct
SMemAllocatorFactory
*
);
void
(
*
destroy
)(
struct
SMemAllocatorFactory
*
,
SMemAllocator
*
);
}
SMemAllocatorFactory
;
#ifdef __cplusplus
}
...
...
include/util/tdlist.h
已删除
100644 → 0
浏览文件 @
2e68133e
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_UTIL_TDLIST_H_
#define _TD_UTIL_TDLIST_H_
#ifdef __cplusplus
extern
"C"
{
#endif
// Single linked list
#define TD_SLIST_NODE(TYPE) \
struct { \
struct TYPE *sl_next_; \
}
#define TD_SLIST(TYPE) \
struct { \
struct TYPE *sl_head_; \
int sl_neles_; \
}
#define TD_SLIST_HEAD(sl) ((sl)->sl_head_)
#define TD_SLIST_NELES(sl) ((sl)->sl_neles_)
#define TD_SLIST_NODE_NEXT(sln) ((sln)->sl_next_)
#define tSListInit(sl) \
do { \
(sl)->sl_head_ = NULL; \
(sl)->sl_neles_ = 0; \
} while (0)
#define tSListPush(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) \
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 { \
struct TYPE *dl_prev_; \
struct TYPE *dl_next_; \
}
#define TD_DLIST(TYPE) \
struct { \
struct TYPE *dl_head_; \
struct TYPE *dl_tail_; \
int dl_neles_; \
}
#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 tDListInit(dl) \
do { \
TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = NULL; \
TD_DLIST_NELES(dl) = 0; \
} while (0)
#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
#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) \
(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) \
({ \
(it)->it_ptr_ = (it)->it_next_; \
if ((it)->it_next_ != NULL) { \
if ((it)->it_dir_ == TD_LIST_FITER) { \
(it)->it_next_ = (it)->it_next_->next_; \
} else { \
(it)->it_next_ = (it)->it_next_->prev_; \
} \
} \
(it)->it_ptr_; \
})
#endif
#ifdef __cplusplus
}
#endif
#endif
/*_TD_UTIL_TDLIST_H_*/
\ No newline at end of file
include/util/tlist.h
浏览文件 @
4383b4d6
...
...
@@ -19,19 +19,124 @@
extern
"C"
{
#endif
// Single linked list ================
#define TD_SLIST_NODE(TYPE) \
struct { \
struct TYPE *sl_next_; \
}
#define TD_SLIST(TYPE) \
struct { \
struct TYPE *sl_head_; \
int sl_neles_; \
}
#define TD_SLIST_HEAD(sl) ((sl)->sl_head_)
#define TD_SLIST_NELES(sl) ((sl)->sl_neles_)
#define TD_SLIST_NODE_NEXT(sln) ((sln)->sl_next_)
#define TD_SLIST_INIT(sl) \
do { \
(sl)->sl_head_ = NULL; \
(sl)->sl_neles_ = 0; \
} while (0)
#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 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 ================
#define TD_DLIST_NODE(TYPE) \
struct { \
struct TYPE *dl_prev_; \
struct TYPE *dl_next_; \
}
#define TD_DLIST(TYPE) \
struct { \
struct TYPE *dl_head_; \
struct TYPE *dl_tail_; \
int dl_neles_; \
}
#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 TD_DLIST_INIT(dl) \
do { \
TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = NULL; \
TD_DLIST_NELES(dl) = 0; \
} while (0)
#define TD_DLIST_APPEND(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 TD_DLIST_PREPEND(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 TD_DLIST_POP(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)
// 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
{
...
...
@@ -39,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/inc/vnodeDef.h
浏览文件 @
4383b4d6
...
...
@@ -19,7 +19,7 @@
#include "mallocator.h"
#include "sync.h"
#include "tcoding.h"
#include "t
d
list.h"
#include "tlist.h"
#include "tlockfree.h"
#include "tmacro.h"
#include "wal.h"
...
...
source/dnode/vnode/impl/src/vnodeArenaMAImpl.c
浏览文件 @
4383b4d6
...
...
@@ -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
浏览文件 @
4383b4d6
...
...
@@ -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));
...
...
@@ -168,11 +168,7 @@ static SMemAllocator *vBufPoolCreateMA(SMemAllocatorFactory *pMAF) {
pWrapper
->
pVMA
=
pVnode
->
pBufPool
->
inuse
;
pMA
->
impl
=
pWrapper
;
pMA
->
malloc
=
vmaMaloocCb
;
pMA
->
calloc
=
NULL
;
pMA
->
realloc
=
NULL
;
pMA
->
free
=
NULL
;
pMA
->
usage
=
NULL
;
TD_MA_MALLOC_FUNC
(
pMA
)
=
vmaMaloocCb
;
return
pMA
;
}
...
...
@@ -184,7 +180,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
浏览文件 @
4383b4d6
...
...
@@ -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/inc/tsdbDef.h
浏览文件 @
4383b4d6
...
...
@@ -18,7 +18,7 @@
#include "mallocator.h"
#include "taosmsg.h"
#include "t
d
list.h"
#include "tlist.h"
#include "thash.h"
#include "tskiplist.h"
...
...
source/dnode/vnode/tsdb/src/tsdbMemTable.c
浏览文件 @
4383b4d6
...
...
@@ -50,7 +50,7 @@ STsdbMemTable *tsdbNewMemTable(SMemAllocatorFactory *pMAF) {
pMA
=
(
*
pMAF
->
create
)(
pMAF
);
ASSERT
(
pMA
!=
NULL
);
pMemTable
=
(
STsdbMemTable
*
)
((
*
pMA
->
malloc
)(
pMA
,
sizeof
(
*
pMemTable
)
));
pMemTable
=
(
STsdbMemTable
*
)
TD_MA_MALLOC
(
pMA
,
sizeof
(
*
pMemTable
));
if
(
pMemTable
==
NULL
)
{
(
*
pMAF
->
destroy
)(
pMAF
,
pMA
);
return
NULL
;
...
...
@@ -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
;
...
...
@@ -71,7 +71,7 @@ STsdbMemTable *tsdbNewMemTable(SMemAllocatorFactory *pMAF) {
void
tsdbFreeMemTable
(
SMemAllocatorFactory
*
pMAF
,
STsdbMemTable
*
pMemTable
)
{
SMemAllocator
*
pMA
=
pMemTable
->
pMA
;
if
(
pMA
->
free
)
{
if
(
TD_MA_FREE_FUNC
(
pMA
)
!=
NULL
)
{
// TODO
ASSERT
(
0
);
}
...
...
@@ -81,12 +81,12 @@ void tsdbFreeMemTable(SMemAllocatorFactory *pMAF, STsdbMemTable *pMemTable) {
int
tsdbInsertDataToMemTable
(
STsdbMemTable
*
pMemTable
,
SSubmitMsg
*
pMsg
)
{
SMemAllocator
*
pMA
=
pMemTable
->
pMA
;
STbData
*
pTbData
=
(
STbData
*
)
((
*
pMA
->
malloc
)(
pMA
,
sizeof
(
*
pTbData
)
));
STbData
*
pTbData
=
(
STbData
*
)
TD_MA_MALLOC
(
pMA
,
sizeof
(
*
pTbData
));
if
(
pTbData
==
NULL
)
{
// TODO
}
tSListPush
(
&
(
pMemTable
->
list
),
pTbData
);
TD_SLIST_PUSH
(
&
(
pMemTable
->
list
),
pTbData
);
return
0
;
}
...
...
source/util/CMakeLists.txt
浏览文件 @
4383b4d6
configure_file
(
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/src/version.c.in"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/src/version.c"
)
aux_source_directory
(
src UTIL_SRC
)
add_library
(
util STATIC
${
UTIL_SRC
}
)
target_include_directories
(
...
...
@@ -11,6 +12,4 @@ target_link_libraries(
PUBLIC zlib
PUBLIC lz4_static
PUBLIC api
)
CONFIGURE_FILE
(
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/src/version.c.in"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/src/version.c"
)
)
\ No newline at end of file
source/util/src/mallocator.c
浏览文件 @
4383b4d6
...
...
@@ -16,6 +16,7 @@
#include "mallocator.h"
/* ------------------------ HEAP ALLOCATOR ------------------------ */
#if 0
typedef struct {
size_t tusage;
} SHeapAllocator;
...
...
@@ -104,4 +105,5 @@ static size_t haUsage(SMemAllocator *pma) { return ((SHeapAllocator *)(pma->impl
/* ------------------------ ARENA ALLOCATOR ------------------------ */
typedef struct {
size_t usage;
}
SArenaAllocator
;
\ No newline at end of file
} SArenaAllocator;
#endif
\ No newline at end of file
source/util/src/tlist.c
浏览文件 @
4383b4d6
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录