Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
loser646
TDengine
提交
48c60fd0
T
TDengine
项目概览
loser646
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
48c60fd0
编写于
11月 11, 2019
作者:
weixin_48148422
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update timer log format
上级
1f78d9b8
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
19 addition
and
16 deletion
+19
-16
src/util/src/ttimer.c
src/util/src/ttimer.c
+19
-16
未找到文件。
src/util/src/ttimer.c
浏览文件 @
48c60fd0
...
@@ -132,7 +132,7 @@ static void unlockTimerList(timer_list_t* list) {
...
@@ -132,7 +132,7 @@ static void unlockTimerList(timer_list_t* list) {
int64_t
tid
=
taosGetPthreadId
();
int64_t
tid
=
taosGetPthreadId
();
if
(
__sync_val_compare_and_swap_64
(
&
(
list
->
lockedBy
),
tid
,
0
)
!=
tid
)
{
if
(
__sync_val_compare_and_swap_64
(
&
(
list
->
lockedBy
),
tid
,
0
)
!=
tid
)
{
assert
(
false
);
assert
(
false
);
tmrError
(
"
trying to unlock a timer list not locked by current thread."
);
tmrError
(
"
%d trying to unlock a timer list not locked by current thread."
,
tid
);
}
}
}
}
...
@@ -259,13 +259,13 @@ static void processExpiredTimer(void* handle, void* arg) {
...
@@ -259,13 +259,13 @@ static void processExpiredTimer(void* handle, void* arg) {
timer
->
executedBy
=
taosGetPthreadId
();
timer
->
executedBy
=
taosGetPthreadId
();
uint8_t
state
=
__sync_val_compare_and_swap_8
(
&
timer
->
state
,
TIMER_STATE_WAITING
,
TIMER_STATE_EXPIRED
);
uint8_t
state
=
__sync_val_compare_and_swap_8
(
&
timer
->
state
,
TIMER_STATE_WAITING
,
TIMER_STATE_EXPIRED
);
if
(
state
==
TIMER_STATE_WAITING
)
{
if
(
state
==
TIMER_STATE_WAITING
)
{
const
char
*
fmt
=
"
timer[label=%s,
id=%lld, fp=%p, param=%p] execution start."
;
const
char
*
fmt
=
"
%s timer[
id=%lld, fp=%p, param=%p] execution start."
;
tmrTrace
(
fmt
,
timer
->
ctrl
->
label
,
timer
->
id
,
timer
->
fp
,
timer
->
param
);
tmrTrace
(
fmt
,
timer
->
ctrl
->
label
,
timer
->
id
,
timer
->
fp
,
timer
->
param
);
(
*
timer
->
fp
)(
timer
->
param
,
(
tmr_h
)
timer
->
id
);
(
*
timer
->
fp
)(
timer
->
param
,
(
tmr_h
)
timer
->
id
);
atomic_store_8
(
&
timer
->
state
,
TIMER_STATE_STOPPED
);
atomic_store_8
(
&
timer
->
state
,
TIMER_STATE_STOPPED
);
fmt
=
"
timer[label=%s,
id=%lld, fp=%p, param=%p] execution end."
;
fmt
=
"
%s timer[
id=%lld, fp=%p, param=%p] execution end."
;
tmrTrace
(
fmt
,
timer
->
ctrl
->
label
,
timer
->
id
,
timer
->
fp
,
timer
->
param
);
tmrTrace
(
fmt
,
timer
->
ctrl
->
label
,
timer
->
id
,
timer
->
fp
,
timer
->
param
);
}
}
removeTimer
(
timer
->
id
);
removeTimer
(
timer
->
id
);
...
@@ -273,18 +273,21 @@ static void processExpiredTimer(void* handle, void* arg) {
...
@@ -273,18 +273,21 @@ static void processExpiredTimer(void* handle, void* arg) {
}
}
static
void
addToExpired
(
tmr_obj_t
*
head
)
{
static
void
addToExpired
(
tmr_obj_t
*
head
)
{
const
char
*
fmt
=
"
timer[label=%s, id=%lld, fp=%p, param=%p] expired
"
;
const
char
*
fmt
=
"
%s adding expired timer[id=%lld, fp=%p, param=%p] to queue.
"
;
while
(
head
!=
NULL
)
{
while
(
head
!=
NULL
)
{
tmrTrace
(
fmt
,
head
->
ctrl
->
label
,
head
->
id
,
head
->
fp
,
head
->
param
);
uintptr_t
id
=
head
->
id
;
tmr_obj_t
*
next
=
head
->
next
;
tmr_obj_t
*
next
=
head
->
next
;
tmrTrace
(
fmt
,
head
->
ctrl
->
label
,
id
,
head
->
fp
,
head
->
param
);
SSchedMsg
schedMsg
;
SSchedMsg
schedMsg
;
schedMsg
.
fp
=
NULL
;
schedMsg
.
fp
=
NULL
;
schedMsg
.
tfp
=
processExpiredTimer
;
schedMsg
.
tfp
=
processExpiredTimer
;
schedMsg
.
ahandle
=
head
;
schedMsg
.
ahandle
=
head
;
schedMsg
.
thandle
=
NULL
;
schedMsg
.
thandle
=
NULL
;
taosScheduleTask
(
tmrQhandle
,
&
schedMsg
);
taosScheduleTask
(
tmrQhandle
,
&
schedMsg
);
tmrTrace
(
"timer[id=%lld] has been added to queue."
,
id
);
head
=
next
;
head
=
next
;
}
}
}
}
...
@@ -298,7 +301,7 @@ static uintptr_t doStartTimer(tmr_obj_t* timer, TAOS_TMR_CALLBACK fp, int msecon
...
@@ -298,7 +301,7 @@ static uintptr_t doStartTimer(tmr_obj_t* timer, TAOS_TMR_CALLBACK fp, int msecon
timer
->
ctrl
=
ctrl
;
timer
->
ctrl
=
ctrl
;
addTimer
(
timer
);
addTimer
(
timer
);
const
char
*
fmt
=
"
timer[label=%s,
id=%lld, fp=%p, param=%p] started"
;
const
char
*
fmt
=
"
%s timer[
id=%lld, fp=%p, param=%p] started"
;
tmrTrace
(
fmt
,
ctrl
->
label
,
timer
->
id
,
timer
->
fp
,
timer
->
param
);
tmrTrace
(
fmt
,
ctrl
->
label
,
timer
->
id
,
timer
->
fp
,
timer
->
param
);
if
(
mseconds
==
0
)
{
if
(
mseconds
==
0
)
{
...
@@ -321,7 +324,7 @@ tmr_h taosTmrStart(TAOS_TMR_CALLBACK fp, int mseconds, void* param, void* handle
...
@@ -321,7 +324,7 @@ tmr_h taosTmrStart(TAOS_TMR_CALLBACK fp, int mseconds, void* param, void* handle
tmr_obj_t
*
timer
=
(
tmr_obj_t
*
)
calloc
(
1
,
sizeof
(
tmr_obj_t
));
tmr_obj_t
*
timer
=
(
tmr_obj_t
*
)
calloc
(
1
,
sizeof
(
tmr_obj_t
));
if
(
timer
==
NULL
)
{
if
(
timer
==
NULL
)
{
tmrError
(
"
failed to allocated memory for new timer object."
);
tmrError
(
"
%s failed to allocated memory for new timer object."
,
ctrl
->
label
);
return
NULL
;
return
NULL
;
}
}
...
@@ -392,7 +395,7 @@ static bool doStopTimer(tmr_obj_t* timer, uint8_t state) {
...
@@ -392,7 +395,7 @@ static bool doStopTimer(tmr_obj_t* timer, uint8_t state) {
// we cannot guarantee the thread safety of the timr in all other cases.
// we cannot guarantee the thread safety of the timr in all other cases.
reusable
=
true
;
reusable
=
true
;
}
}
const
char
*
fmt
=
"
timer[label=%s,
id=%lld, fp=%p, param=%p] is cancelled."
;
const
char
*
fmt
=
"
%s timer[
id=%lld, fp=%p, param=%p] is cancelled."
;
tmrTrace
(
fmt
,
timer
->
ctrl
->
label
,
timer
->
id
,
timer
->
fp
,
timer
->
param
);
tmrTrace
(
fmt
,
timer
->
ctrl
->
label
,
timer
->
id
,
timer
->
fp
,
timer
->
param
);
}
else
if
(
state
!=
TIMER_STATE_EXPIRED
)
{
}
else
if
(
state
!=
TIMER_STATE_EXPIRED
)
{
// timer already stopped or cancelled, has nothing to do in this case
// timer already stopped or cancelled, has nothing to do in this case
...
@@ -403,7 +406,7 @@ static bool doStopTimer(tmr_obj_t* timer, uint8_t state) {
...
@@ -403,7 +406,7 @@ static bool doStopTimer(tmr_obj_t* timer, uint8_t state) {
}
else
{
}
else
{
assert
(
timer
->
executedBy
!=
taosGetPthreadId
());
assert
(
timer
->
executedBy
!=
taosGetPthreadId
());
const
char
*
fmt
=
"
timer[label=%s,
id=%lld, fp=%p, param=%p] fired, waiting..."
;
const
char
*
fmt
=
"
%s timer[
id=%lld, fp=%p, param=%p] fired, waiting..."
;
tmrTrace
(
fmt
,
timer
->
ctrl
->
label
,
timer
->
id
,
timer
->
fp
,
timer
->
param
);
tmrTrace
(
fmt
,
timer
->
ctrl
->
label
,
timer
->
id
,
timer
->
fp
,
timer
->
param
);
for
(
int
i
=
1
;
atomic_load_8
(
&
timer
->
state
)
!=
TIMER_STATE_STOPPED
;
i
++
)
{
for
(
int
i
=
1
;
atomic_load_8
(
&
timer
->
state
)
!=
TIMER_STATE_STOPPED
;
i
++
)
{
...
@@ -412,7 +415,7 @@ static bool doStopTimer(tmr_obj_t* timer, uint8_t state) {
...
@@ -412,7 +415,7 @@ static bool doStopTimer(tmr_obj_t* timer, uint8_t state) {
}
}
}
}
fmt
=
"
timer[label=%s,
id=%lld, fp=%p, param=%p] stopped."
;
fmt
=
"
%s timer[
id=%lld, fp=%p, param=%p] stopped."
;
tmrTrace
(
fmt
,
timer
->
ctrl
->
label
,
timer
->
id
,
timer
->
fp
,
timer
->
param
);
tmrTrace
(
fmt
,
timer
->
ctrl
->
label
,
timer
->
id
,
timer
->
fp
,
timer
->
param
);
}
}
...
@@ -451,7 +454,7 @@ bool taosTmrReset(TAOS_TMR_CALLBACK fp, int mseconds, void* param, void* handle,
...
@@ -451,7 +454,7 @@ bool taosTmrReset(TAOS_TMR_CALLBACK fp, int mseconds, void* param, void* handle,
bool
stopped
=
false
;
bool
stopped
=
false
;
tmr_obj_t
*
timer
=
findTimer
(
id
);
tmr_obj_t
*
timer
=
findTimer
(
id
);
if
(
timer
==
NULL
)
{
if
(
timer
==
NULL
)
{
tmrTrace
(
"
timer[id=%lld] does not exist"
,
id
);
tmrTrace
(
"
%s timer[id=%lld] does not exist"
,
ctrl
->
label
,
id
);
}
else
{
}
else
{
uint8_t
state
=
__sync_val_compare_and_swap_8
(
&
timer
->
state
,
TIMER_STATE_WAITING
,
TIMER_STATE_CANCELED
);
uint8_t
state
=
__sync_val_compare_and_swap_8
(
&
timer
->
state
,
TIMER_STATE_WAITING
,
TIMER_STATE_CANCELED
);
if
(
!
doStopTimer
(
timer
,
state
))
{
if
(
!
doStopTimer
(
timer
,
state
))
{
...
@@ -466,7 +469,7 @@ bool taosTmrReset(TAOS_TMR_CALLBACK fp, int mseconds, void* param, void* handle,
...
@@ -466,7 +469,7 @@ bool taosTmrReset(TAOS_TMR_CALLBACK fp, int mseconds, void* param, void* handle,
return
stopped
;
return
stopped
;
}
}
tmrTrace
(
"
timer[id=%lld] is reused"
,
timer
->
id
);
tmrTrace
(
"
%s timer[id=%lld] is reused"
,
ctrl
->
label
,
timer
->
id
);
// wait until there's no other reference to this timer,
// wait until there's no other reference to this timer,
// so that we can reuse this timer safely.
// so that we can reuse this timer safely.
...
@@ -540,13 +543,13 @@ void* taosTmrInit(int maxNumOfTmrs, int resolution, int longest, const char* lab
...
@@ -540,13 +543,13 @@ void* taosTmrInit(int maxNumOfTmrs, int resolution, int longest, const char* lab
pthread_mutex_unlock
(
&
tmrCtrlMutex
);
pthread_mutex_unlock
(
&
tmrCtrlMutex
);
if
(
ctrl
==
NULL
)
{
if
(
ctrl
==
NULL
)
{
tmrError
(
"
too many timer controllers, failed to create timer controller[label=%s]
."
,
label
);
tmrError
(
"
%s too many timer controllers, failed to create timer controller
."
,
label
);
return
NULL
;
return
NULL
;
}
}
strncpy
(
ctrl
->
label
,
label
,
sizeof
(
ctrl
->
label
));
strncpy
(
ctrl
->
label
,
label
,
sizeof
(
ctrl
->
label
));
ctrl
->
label
[
sizeof
(
ctrl
->
label
)
-
1
]
=
0
;
ctrl
->
label
[
sizeof
(
ctrl
->
label
)
-
1
]
=
0
;
tmrTrace
(
"
timer controller[label=%s]
is initialized, number of timer controllers: %d."
,
label
,
numOfTmrCtrl
);
tmrTrace
(
"
%s timer controller
is initialized, number of timer controllers: %d."
,
label
,
numOfTmrCtrl
);
return
ctrl
;
return
ctrl
;
}
}
...
@@ -554,7 +557,7 @@ void taosTmrCleanUp(void* handle) {
...
@@ -554,7 +557,7 @@ void taosTmrCleanUp(void* handle) {
tmr_ctrl_t
*
ctrl
=
(
tmr_ctrl_t
*
)
handle
;
tmr_ctrl_t
*
ctrl
=
(
tmr_ctrl_t
*
)
handle
;
assert
(
ctrl
!=
NULL
&&
ctrl
->
label
[
0
]
!=
0
);
assert
(
ctrl
!=
NULL
&&
ctrl
->
label
[
0
]
!=
0
);
tmrTrace
(
"
timer controller[label=%s]
is cleaned up."
,
ctrl
->
label
);
tmrTrace
(
"
%s timer controller
is cleaned up."
,
ctrl
->
label
);
ctrl
->
label
[
0
]
=
0
;
ctrl
->
label
[
0
]
=
0
;
pthread_mutex_lock
(
&
tmrCtrlMutex
);
pthread_mutex_lock
(
&
tmrCtrlMutex
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录