Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
542da254
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1185
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
542da254
编写于
8月 15, 2019
作者:
H
hzcheng
提交者:
GitHub
8月 15, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #344 from localvar/enhance-scheduler
enhance robustness of scheduler
上级
b3f41997
83eb20d3
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
22 addition
and
6 deletion
+22
-6
src/util/src/tsched.c
src/util/src/tsched.c
+22
-6
未找到文件。
src/util/src/tsched.c
浏览文件 @
542da254
...
...
@@ -38,17 +38,19 @@ typedef struct {
SSchedMsg
*
queue
;
}
SSchedQueue
;
void
(
*
taosSchedFp
[
128
])(
SSchedMsg
*
msg
)
=
{
0
};
void
*
taosProcessSchedQueue
(
void
*
param
);
void
taosCleanUpScheduler
(
void
*
param
);
void
*
taosInitScheduler
(
int
queueSize
,
int
numOfThreads
,
const
char
*
label
)
{
pthread_attr_t
attr
;
SSchedQueue
*
pSched
=
(
SSchedQueue
*
)
malloc
(
sizeof
(
SSchedQueue
));
if
(
pSched
==
NULL
)
{
pError
(
"%s: no enough memory for pSched, reason: %s"
,
label
,
strerror
(
errno
));
goto
_error
;
}
memset
(
pSched
,
0
,
sizeof
(
SSchedQueue
));
pSched
->
queueSize
=
queueSize
;
pSched
->
numOfThreads
=
numOfThreads
;
strncpy
(
pSched
->
label
,
label
,
sizeof
(
pSched
->
label
));
// fix buffer overflow
pSched
->
label
[
sizeof
(
pSched
->
label
)
-
1
]
=
'\0'
;
...
...
@@ -76,16 +78,21 @@ void *taosInitScheduler(int queueSize, int numOfThreads, const char *label) {
pSched
->
fullSlot
=
0
;
pSched
->
emptySlot
=
0
;
pSched
->
qthread
=
malloc
(
sizeof
(
pthread_t
)
*
(
size_t
)
pSched
->
numOfThreads
);
pSched
->
qthread
=
malloc
(
sizeof
(
pthread_t
)
*
(
size_t
)
numOfThreads
);
if
(
pSched
->
qthread
==
NULL
)
{
pError
(
"%s: no enough memory for qthread, reason: %s"
,
pSched
->
label
,
strerror
(
errno
));
goto
_error
;
}
pthread_attr_init
(
&
attr
);
pthread_attr_setdetachstate
(
&
attr
,
PTHREAD_CREATE_JOINABLE
);
for
(
int
i
=
0
;
i
<
pSched
->
numOfThreads
;
++
i
)
{
for
(
int
i
=
0
;
i
<
numOfThreads
;
++
i
)
{
if
(
pthread_create
(
pSched
->
qthread
+
i
,
&
attr
,
taosProcessSchedQueue
,
(
void
*
)
pSched
)
!=
0
)
{
pError
(
"%s: failed to create rpc thread, reason:%s"
,
pSched
->
label
,
strerror
(
errno
));
goto
_error
;
}
++
pSched
->
numOfThreads
;
}
pTrace
(
"%s scheduler is initialized, numOfThreads:%d"
,
pSched
->
label
,
pSched
->
numOfThreads
);
...
...
@@ -103,11 +110,12 @@ void *taosProcessSchedQueue(void *param) {
while
(
1
)
{
if
(
sem_wait
(
&
pSched
->
fullSem
)
!=
0
)
{
pError
(
"wait %s fullSem failed, errno:%d, reason:%s"
,
pSched
->
label
,
errno
,
strerror
(
errno
));
if
(
errno
==
EINTR
)
{
/* sem_wait is interrupted by interrupt, ignore and continue */
pTrace
(
"wait %s fullSem was interrupted"
,
pSched
->
label
);
continue
;
}
pError
(
"wait %s fullSem failed, errno:%d, reason:%s"
,
pSched
->
label
,
errno
,
strerror
(
errno
));
}
if
(
pthread_mutex_lock
(
&
pSched
->
queueMutex
)
!=
0
)
...
...
@@ -137,7 +145,13 @@ int taosScheduleTask(void *qhandle, SSchedMsg *pMsg) {
return
0
;
}
if
(
sem_wait
(
&
pSched
->
emptySem
)
!=
0
)
pError
(
"wait %s emptySem failed, reason:%s"
,
pSched
->
label
,
strerror
(
errno
));
while
(
sem_wait
(
&
pSched
->
emptySem
)
!=
0
)
{
if
(
errno
!=
EINTR
)
{
pError
(
"wait %s emptySem failed, reason:%s"
,
pSched
->
label
,
strerror
(
errno
));
break
;
}
pTrace
(
"wait %s emptySem was interrupted"
,
pSched
->
label
);
}
if
(
pthread_mutex_lock
(
&
pSched
->
queueMutex
)
!=
0
)
pError
(
"lock %s queueMutex failed, reason:%s"
,
pSched
->
label
,
strerror
(
errno
));
...
...
@@ -159,6 +173,8 @@ void taosCleanUpScheduler(void *param) {
for
(
int
i
=
0
;
i
<
pSched
->
numOfThreads
;
++
i
)
{
pthread_cancel
(
pSched
->
qthread
[
i
]);
}
for
(
int
i
=
0
;
i
<
pSched
->
numOfThreads
;
++
i
)
{
pthread_join
(
pSched
->
qthread
[
i
],
NULL
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录