Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8685fb79
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看板
提交
8685fb79
编写于
1月 25, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refact worker
上级
5fca9015
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
56 addition
and
28 deletion
+56
-28
include/util/tqueue.h
include/util/tqueue.h
+1
-0
include/util/tworker.h
include/util/tworker.h
+0
-1
source/util/src/tqueue.c
source/util/src/tqueue.c
+34
-25
source/util/src/tworker.c
source/util/src/tworker.c
+21
-2
未找到文件。
include/util/tqueue.h
浏览文件 @
8685fb79
...
...
@@ -15,6 +15,7 @@
#ifndef _TD_UTIL_QUEUE_H
#define _TD_UTIL_QUEUE_H
#include "os.h"
#ifdef __cplusplus
extern
"C"
{
...
...
include/util/tworker.h
浏览文件 @
8685fb79
...
...
@@ -15,7 +15,6 @@
#ifndef _TD_UTIL_WORKER_H
#define _TD_UTIL_WORKER_H
#include "os.h"
#include "tqueue.h"
#ifdef __cplusplus
...
...
source/util/src/tqueue.c
浏览文件 @
8685fb79
...
...
@@ -13,10 +13,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "os.h"
#include "taoserror.h"
#define _DEFAULT_SOURCE
#include "tqueue.h"
#include "taoserror.h"
#include "ulog.h"
typedef
struct
STaosQnode
STaosQnode
;
...
...
@@ -29,19 +28,19 @@ typedef struct STaosQnode {
typedef
struct
STaosQueue
{
int32_t
itemSize
;
int32_t
numOfItems
;
STaosQnode
*
head
;
STaosQnode
*
tail
;
STaosQueue
*
next
;
// for queue set
STaosQset
*
qset
;
// for queue set
void
*
ahandle
;
// for queue set
STaosQnode
*
head
;
STaosQnode
*
tail
;
STaosQueue
*
next
;
// for queue set
STaosQset
*
qset
;
// for queue set
void
*
ahandle
;
// for queue set
FProcessItem
itemFp
;
FProcessItems
itemsFp
;
pthread_mutex_t
mutex
;
}
STaosQueue
;
typedef
struct
STaosQset
{
STaosQueue
*
head
;
STaosQueue
*
current
;
STaosQueue
*
head
;
STaosQueue
*
current
;
pthread_mutex_t
mutex
;
int32_t
numOfQueues
;
int32_t
numOfItems
;
...
...
@@ -56,15 +55,18 @@ typedef struct STaosQall {
}
STaosQall
;
STaosQueue
*
taosOpenQueue
()
{
STaosQueue
*
queue
=
calloc
(
sizeof
(
STaosQueue
),
1
);
STaosQueue
*
queue
=
calloc
(
1
,
sizeof
(
STaosQueue
)
);
if
(
queue
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
pthread_mutex_init
(
&
queue
->
mutex
,
NULL
);
if
(
pthread_mutex_init
(
&
queue
->
mutex
,
NULL
)
!=
0
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
u
Trace
(
"queue:%p is opened"
,
queue
);
u
Debug
(
"queue:%p is opened"
,
queue
);
return
queue
;
}
...
...
@@ -77,7 +79,7 @@ void taosSetQueueFp(STaosQueue *queue, FProcessItem itemFp, FProcessItems itemsF
void
taosCloseQueue
(
STaosQueue
*
queue
)
{
if
(
queue
==
NULL
)
return
;
STaosQnode
*
pTemp
;
STaosQset
*
qset
;
STaosQset
*
qset
;
pthread_mutex_lock
(
&
queue
->
mutex
);
STaosQnode
*
pNode
=
queue
->
head
;
...
...
@@ -85,7 +87,9 @@ void taosCloseQueue(STaosQueue *queue) {
qset
=
queue
->
qset
;
pthread_mutex_unlock
(
&
queue
->
mutex
);
if
(
queue
->
qset
)
taosRemoveFromQset
(
qset
,
queue
);
if
(
queue
->
qset
)
{
taosRemoveFromQset
(
qset
,
queue
);
}
while
(
pNode
)
{
pTemp
=
pNode
;
...
...
@@ -96,7 +100,7 @@ void taosCloseQueue(STaosQueue *queue) {
pthread_mutex_destroy
(
&
queue
->
mutex
);
free
(
queue
);
u
Trace
(
"queue:%p is closed"
,
queue
);
u
Debug
(
"queue:%p is closed"
,
queue
);
}
bool
taosQueueEmpty
(
STaosQueue
*
queue
)
{
...
...
@@ -120,9 +124,13 @@ int32_t taosQueueSize(STaosQueue *queue) {
}
void
*
taosAllocateQitem
(
int32_t
size
)
{
STaosQnode
*
pNode
=
(
STaosQnode
*
)
calloc
(
sizeof
(
STaosQnode
)
+
size
,
1
);
STaosQnode
*
pNode
=
calloc
(
1
,
sizeof
(
STaosQnode
)
+
size
);
if
(
pNode
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
if
(
pNode
==
NULL
)
return
NULL
;
uTrace
(
"item:%p, node:%p is allocated"
,
pNode
->
item
,
pNode
);
return
(
void
*
)
pNode
->
item
;
}
...
...
@@ -130,7 +138,7 @@ void *taosAllocateQitem(int32_t size) {
void
taosFreeQitem
(
void
*
param
)
{
if
(
param
==
NULL
)
return
;
char
*
temp
=
(
char
*
)
param
;
char
*
temp
=
param
;
temp
-=
sizeof
(
STaosQnode
);
uTrace
(
"item:%p, node:%p is freed"
,
param
,
temp
);
free
(
temp
);
...
...
@@ -175,7 +183,7 @@ int32_t taosReadQitem(STaosQueue *queue, void **ppItem) {
queue
->
numOfItems
--
;
if
(
queue
->
qset
)
atomic_sub_fetch_32
(
&
queue
->
qset
->
numOfItems
,
1
);
code
=
1
;
u
Debug
(
"item:%p is read out from queue:%p, items:%d"
,
*
ppItem
,
queue
,
queue
->
numOfItems
);
u
Trace
(
"item:%p is read out from queue:%p, items:%d"
,
*
ppItem
,
queue
,
queue
->
numOfItems
);
}
pthread_mutex_unlock
(
&
queue
->
mutex
);
...
...
@@ -183,7 +191,7 @@ int32_t taosReadQitem(STaosQueue *queue, void **ppItem) {
return
code
;
}
STaosQall
*
taosAllocateQall
()
{
return
calloc
(
sizeof
(
STaosQall
),
1
);
}
STaosQall
*
taosAllocateQall
()
{
return
calloc
(
1
,
sizeof
(
STaosQall
)
);
}
void
taosFreeQall
(
STaosQall
*
qall
)
{
free
(
qall
);
}
...
...
@@ -238,7 +246,7 @@ int32_t taosGetQitem(STaosQall *qall, void **ppItem) {
void
taosResetQitems
(
STaosQall
*
qall
)
{
qall
->
current
=
qall
->
start
;
}
STaosQset
*
taosOpenQset
()
{
STaosQset
*
qset
=
(
STaosQset
*
)
calloc
(
sizeof
(
STaosQset
),
1
);
STaosQset
*
qset
=
calloc
(
sizeof
(
STaosQset
),
1
);
if
(
qset
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
...
...
@@ -247,7 +255,7 @@ STaosQset *taosOpenQset() {
pthread_mutex_init
(
&
qset
->
mutex
,
NULL
);
tsem_init
(
&
qset
->
sem
,
0
,
0
);
u
Trace
(
"qset:%p is opened"
,
qset
);
u
Debug
(
"qset:%p is opened"
,
qset
);
return
qset
;
}
...
...
@@ -268,7 +276,7 @@ void taosCloseQset(STaosQset *qset) {
pthread_mutex_destroy
(
&
qset
->
mutex
);
tsem_destroy
(
&
qset
->
sem
);
free
(
qset
);
u
Trace
(
"qset:%p is closed"
,
qset
);
u
Debug
(
"qset:%p is closed"
,
qset
);
}
// tsem_post 'qset->sem', so that reader threads waiting for it
...
...
@@ -338,7 +346,7 @@ void taosRemoveFromQset(STaosQset *qset, STaosQueue *queue) {
pthread_mutex_unlock
(
&
qset
->
mutex
);
u
Trace
(
"queue:%p is removed from qset:%p"
,
queue
,
qset
);
u
Debug
(
"queue:%p is removed from qset:%p"
,
queue
,
qset
);
}
int32_t
taosGetQueueNumber
(
STaosQset
*
qset
)
{
return
qset
->
numOfQueues
;
}
...
...
@@ -365,6 +373,7 @@ int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, void **ahandle, FP
*
ppItem
=
pNode
->
item
;
if
(
ahandle
)
*
ahandle
=
queue
->
ahandle
;
if
(
itemFp
)
*
itemFp
=
queue
->
itemFp
;
queue
->
head
=
pNode
->
next
;
if
(
queue
->
head
==
NULL
)
queue
->
tail
=
NULL
;
queue
->
numOfItems
--
;
...
...
source/util/src/tworker.c
浏览文件 @
8685fb79
...
...
@@ -15,6 +15,7 @@
#define _DEFAULT_SOURCE
#include "tworker.h"
#include "taoserror.h"
#include "ulog.h"
typedef
void
*
(
*
ThreadFp
)(
void
*
param
);
...
...
@@ -22,7 +23,13 @@ typedef void *(*ThreadFp)(void *param);
int32_t
tQWorkerInit
(
SQWorkerPool
*
pool
)
{
pool
->
qset
=
taosOpenQset
();
pool
->
workers
=
calloc
(
sizeof
(
SQWorker
),
pool
->
max
);
if
(
pool
->
workers
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
if
(
pthread_mutex_init
(
&
pool
->
mutex
,
NULL
))
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
...
...
@@ -91,6 +98,7 @@ STaosQueue *tQWorkerAllocQueue(SQWorkerPool *pool, void *ahandle, FProcessItem f
STaosQueue
*
queue
=
taosOpenQueue
();
if
(
queue
==
NULL
)
{
pthread_mutex_unlock
(
&
pool
->
mutex
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
...
...
@@ -109,6 +117,7 @@ STaosQueue *tQWorkerAllocQueue(SQWorkerPool *pool, void *ahandle, FProcessItem f
if
(
pthread_create
(
&
worker
->
thread
,
&
thAttr
,
(
ThreadFp
)
tQWorkerThreadFp
,
worker
)
!=
0
)
{
uError
(
"qworker:%s:%d failed to create thread to process since %s"
,
pool
->
name
,
worker
->
id
,
strerror
(
errno
));
taosCloseQueue
(
queue
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
queue
=
NULL
;
break
;
}
...
...
@@ -133,9 +142,16 @@ void tQWorkerFreeQueue(SQWorkerPool *pool, STaosQueue *queue) {
int32_t
tWWorkerInit
(
SWWorkerPool
*
pool
)
{
pool
->
nextId
=
0
;
pool
->
workers
=
calloc
(
sizeof
(
SWWorker
),
pool
->
max
);
if
(
pool
->
workers
==
NULL
)
return
-
1
;
if
(
pool
->
workers
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
if
(
pthread_mutex_init
(
&
pool
->
mutex
,
NULL
)
!=
0
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
pthread_mutex_init
(
&
pool
->
mutex
,
NULL
);
for
(
int32_t
i
=
0
;
i
<
pool
->
max
;
++
i
)
{
SWWorker
*
worker
=
pool
->
workers
+
i
;
worker
->
id
=
i
;
...
...
@@ -208,6 +224,7 @@ STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FProcessItems
STaosQueue
*
queue
=
taosOpenQueue
();
if
(
queue
==
NULL
)
{
pthread_mutex_unlock
(
&
pool
->
mutex
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
...
...
@@ -227,6 +244,7 @@ STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FProcessItems
taosCloseQset
(
worker
->
qset
);
taosCloseQueue
(
queue
);
pthread_mutex_unlock
(
&
pool
->
mutex
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
pthread_attr_t
thAttr
;
...
...
@@ -238,6 +256,7 @@ STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FProcessItems
taosFreeQall
(
worker
->
qall
);
taosCloseQset
(
worker
->
qset
);
taosCloseQueue
(
queue
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
queue
=
NULL
;
}
else
{
uDebug
(
"wworker:%s:%d is launched, max:%d"
,
pool
->
name
,
worker
->
id
,
pool
->
max
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录