Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
fe632ad6
T
TDengine
项目概览
taosdata
/
TDengine
12 个月 前同步成功
通知
1181
Star
22014
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fe632ad6
编写于
11月 22, 2019
作者:
weixin_48148422
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix TBASE-1217
上级
9eb6d735
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
27 addition
and
29 deletion
+27
-29
src/util/src/ttimer.c
src/util/src/ttimer.c
+27
-29
未找到文件。
src/util/src/ttimer.c
浏览文件 @
fe632ad6
...
...
@@ -14,6 +14,7 @@
*/
#include "os.h"
#include <inttypes.h>
#include "tlog.h"
#include "tsched.h"
#include "ttime.h"
...
...
@@ -253,13 +254,13 @@ static void processExpiredTimer(void* handle, void* arg) {
timer
->
executedBy
=
taosGetPthreadId
();
uint8_t
state
=
atomic_val_compare_exchange_8
(
&
timer
->
state
,
TIMER_STATE_WAITING
,
TIMER_STATE_EXPIRED
);
if
(
state
==
TIMER_STATE_WAITING
)
{
const
char
*
fmt
=
"%s timer[id=
%lld
, fp=%p, param=%p] execution start."
;
const
char
*
fmt
=
"%s timer[id=
"
PRIuPTR
"
, fp=%p, param=%p] execution start."
;
tmrTrace
(
fmt
,
timer
->
ctrl
->
label
,
timer
->
id
,
timer
->
fp
,
timer
->
param
);
(
*
timer
->
fp
)(
timer
->
param
,
(
tmr_h
)
timer
->
id
);
atomic_store_8
(
&
timer
->
state
,
TIMER_STATE_STOPPED
);
fmt
=
"%s timer[id=
%lld
, fp=%p, param=%p] execution end."
;
fmt
=
"%s timer[id=
"
PRIuPTR
"
, fp=%p, param=%p] execution end."
;
tmrTrace
(
fmt
,
timer
->
ctrl
->
label
,
timer
->
id
,
timer
->
fp
,
timer
->
param
);
}
removeTimer
(
timer
->
id
);
...
...
@@ -267,7 +268,7 @@ static void processExpiredTimer(void* handle, void* arg) {
}
static
void
addToExpired
(
tmr_obj_t
*
head
)
{
const
char
*
fmt
=
"%s adding expired timer[id=
%lld
, fp=%p, param=%p] to queue."
;
const
char
*
fmt
=
"%s adding expired timer[id=
"
PRIuPTR
"
, fp=%p, param=%p] to queue."
;
while
(
head
!=
NULL
)
{
uintptr_t
id
=
head
->
id
;
...
...
@@ -281,7 +282,7 @@ static void addToExpired(tmr_obj_t* head) {
schedMsg
.
thandle
=
NULL
;
taosScheduleTask
(
tmrQhandle
,
&
schedMsg
);
tmrTrace
(
"timer[id=
%lld
] has been added to queue."
,
id
);
tmrTrace
(
"timer[id=
"
PRIuPTR
"
] has been added to queue."
,
id
);
head
=
next
;
}
}
...
...
@@ -295,7 +296,7 @@ static uintptr_t doStartTimer(tmr_obj_t* timer, TAOS_TMR_CALLBACK fp, int msecon
timer
->
ctrl
=
ctrl
;
addTimer
(
timer
);
const
char
*
fmt
=
"%s timer[id=
%lld
, fp=%p, param=%p] started"
;
const
char
*
fmt
=
"%s timer[id=
"
PRIuPTR
"
, fp=%p, param=%p] started"
;
tmrTrace
(
fmt
,
ctrl
->
label
,
timer
->
id
,
timer
->
fp
,
timer
->
param
);
if
(
mseconds
==
0
)
{
...
...
@@ -380,40 +381,37 @@ static void taosTimerLoopFunc(int signo) {
}
static
bool
doStopTimer
(
tmr_obj_t
*
timer
,
uint8_t
state
)
{
bool
reusable
=
false
;
if
(
state
==
TIMER_STATE_WAITING
)
{
bool
reusable
=
false
;
if
(
removeFromWheel
(
timer
))
{
removeTimer
(
timer
->
id
);
// only safe to reuse the timer when timer is removed from the wheel.
// we cannot guarantee the thread safety of the timr in all other cases.
reusable
=
true
;
}
const
char
*
fmt
=
"%s timer[id=
%lld
, fp=%p, param=%p] is cancelled."
;
const
char
*
fmt
=
"%s timer[id=
"
PRIuPTR
"
, fp=%p, param=%p] is cancelled."
;
tmrTrace
(
fmt
,
timer
->
ctrl
->
label
,
timer
->
id
,
timer
->
fp
,
timer
->
param
);
}
else
if
(
state
!=
TIMER_STATE_EXPIRED
)
{
return
reusable
;
}
if
(
state
!=
TIMER_STATE_EXPIRED
)
{
// timer already stopped or cancelled, has nothing to do in this case
}
else
if
(
timer
->
executedBy
==
taosGetPthreadId
())
{
return
false
;
}
if
(
timer
->
executedBy
==
taosGetPthreadId
())
{
// taosTmrReset is called in the timer callback, should do nothing in this
// case to avoid dead lock. note taosTmrReset must be the last statement
// of the callback funtion, will be a bug otherwise.
}
else
{
assert
(
timer
->
executedBy
!=
taosGetPthreadId
());
const
char
*
fmt
=
"%s timer[id=%lld, fp=%p, param=%p] fired, waiting..."
;
tmrTrace
(
fmt
,
timer
->
ctrl
->
label
,
timer
->
id
,
timer
->
fp
,
timer
->
param
);
for
(
int
i
=
1
;
atomic_load_8
(
&
timer
->
state
)
!=
TIMER_STATE_STOPPED
;
i
++
)
{
if
(
i
%
1000
==
0
)
{
sched_yield
();
}
}
fmt
=
"%s timer[id=%lld, fp=%p, param=%p] stopped."
;
tmrTrace
(
fmt
,
timer
->
ctrl
->
label
,
timer
->
id
,
timer
->
fp
,
timer
->
param
);
return
false
;
}
return
reusable
;
// timer callback is executing in another thread, we SHOULD wait it to stop,
// BUT this may result in dead lock if current thread are holding a lock which
// the timer callback need to acquire. so, we HAVE TO return directly.
const
char
*
fmt
=
"%s timer[id="
PRIuPTR
", fp=%p, param=%p] is executing and cannot be stopped."
;
tmrTrace
(
fmt
,
timer
->
ctrl
->
label
,
timer
->
id
,
timer
->
fp
,
timer
->
param
);
return
false
;
}
bool
taosTmrStop
(
tmr_h
timerId
)
{
...
...
@@ -421,7 +419,7 @@ bool taosTmrStop(tmr_h timerId) {
tmr_obj_t
*
timer
=
findTimer
(
id
);
if
(
timer
==
NULL
)
{
tmrTrace
(
"timer[id=
%lld
] does not exist"
,
id
);
tmrTrace
(
"timer[id=
"
PRIuPTR
"
] does not exist"
,
id
);
return
false
;
}
...
...
@@ -448,7 +446,7 @@ bool taosTmrReset(TAOS_TMR_CALLBACK fp, int mseconds, void* param, void* handle,
bool
stopped
=
false
;
tmr_obj_t
*
timer
=
findTimer
(
id
);
if
(
timer
==
NULL
)
{
tmrTrace
(
"%s timer[id=
%lld
] does not exist"
,
ctrl
->
label
,
id
);
tmrTrace
(
"%s timer[id=
"
PRIuPTR
"
] does not exist"
,
ctrl
->
label
,
id
);
}
else
{
uint8_t
state
=
atomic_val_compare_exchange_8
(
&
timer
->
state
,
TIMER_STATE_WAITING
,
TIMER_STATE_CANCELED
);
if
(
!
doStopTimer
(
timer
,
state
))
{
...
...
@@ -463,7 +461,7 @@ bool taosTmrReset(TAOS_TMR_CALLBACK fp, int mseconds, void* param, void* handle,
return
stopped
;
}
tmrTrace
(
"%s timer[id=
%lld
] is reused"
,
ctrl
->
label
,
timer
->
id
);
tmrTrace
(
"%s timer[id=
"
PRIuPTR
"
] is reused"
,
ctrl
->
label
,
timer
->
id
);
// wait until there's no other reference to this timer,
// so that we can reuse this timer safely.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录