Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
13981723
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
13981723
编写于
2月 28, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
timer
上级
e14308c5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
24 addition
and
25 deletion
+24
-25
include/util/ttimer.h
include/util/ttimer.h
+8
-8
source/util/src/ttimer.c
source/util/src/ttimer.c
+16
-17
未找到文件。
include/util/ttimer.h
浏览文件 @
13981723
...
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_UTIL_TIMER_H
#define _TD_UTIL_TIMER_H
#ifndef _TD_UTIL_TIMER_H
_
#define _TD_UTIL_TIMER_H
_
#include "os.h"
...
...
@@ -25,23 +25,23 @@ extern "C" {
typedef
void
*
tmr_h
;
typedef
void
(
*
TAOS_TMR_CALLBACK
)(
void
*
,
void
*
);
extern
int
taosTmrThreads
;
extern
int
32_t
taosTmrThreads
;
#define MSECONDS_PER_TICK 5
void
*
taosTmrInit
(
int
maxTmr
,
int
resoultion
,
in
t
longest
,
const
char
*
label
);
void
*
taosTmrInit
(
int
32_t
maxTmr
,
int32_t
resoultion
,
int32_
t
longest
,
const
char
*
label
);
tmr_h
taosTmrStart
(
TAOS_TMR_CALLBACK
fp
,
int
mseconds
,
void
*
param
,
void
*
handle
);
tmr_h
taosTmrStart
(
TAOS_TMR_CALLBACK
fp
,
int
32_t
mseconds
,
void
*
param
,
void
*
handle
);
bool
taosTmrStop
(
tmr_h
tmrId
);
bool
taosTmrStopA
(
tmr_h
*
timerId
);
bool
taosTmrReset
(
TAOS_TMR_CALLBACK
fp
,
int
mseconds
,
void
*
param
,
void
*
handle
,
tmr_h
*
pTmrId
);
bool
taosTmrReset
(
TAOS_TMR_CALLBACK
fp
,
int
32_t
mseconds
,
void
*
param
,
void
*
handle
,
tmr_h
*
pTmrId
);
void
taosTmrCleanUp
(
void
*
handle
);
int32_t
taosInitTimer
(
void
(
*
callback
)(
int
),
int32_t
ms
);
int32_t
taosInitTimer
(
void
(
*
callback
)(
int
32_t
),
int32_t
ms
);
void
taosUninitTimer
();
...
...
@@ -49,4 +49,4 @@ void taosUninitTimer();
}
#endif
#endif
/*_TD_UTIL_TIMER_H
*/
#endif
/*_TD_UTIL_TIMER_H_
*/
source/util/src/ttimer.c
浏览文件 @
13981723
...
...
@@ -13,12 +13,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "ttimer.h"
#include "os.h"
#include "taoserror.h"
#include "tlog.h"
#include "tsched.h"
#include "tutil.h"
#define tmrFatal(...) \
{ \
...
...
@@ -57,9 +56,9 @@
} \
}
#define TIMER_STATE_WAITING 0
#define TIMER_STATE_EXPIRED 1
#define TIMER_STATE_STOPPED 2
#define TIMER_STATE_WAITING
0
#define TIMER_STATE_EXPIRED
1
#define TIMER_STATE_STOPPED
2
#define TIMER_STATE_CANCELED 3
typedef
union
_tmr_ctrl_t
{
...
...
@@ -118,9 +117,9 @@ static pthread_mutex_t tmrCtrlMutex;
static
tmr_ctrl_t
*
tmrCtrls
;
static
tmr_ctrl_t
*
unusedTmrCtrl
=
NULL
;
static
void
*
tmrQhandle
;
static
int
numOfTmrCtrl
=
0
;
static
int
32_t
numOfTmrCtrl
=
0
;
int
taosTmrThreads
=
1
;
int
32_t
taosTmrThreads
=
1
;
static
uintptr_t
nextTimerId
=
0
;
static
time_wheel_t
wheels
[]
=
{
...
...
@@ -148,7 +147,7 @@ static void timerDecRef(tmr_obj_t* timer) {
static
void
lockTimerList
(
timer_list_t
*
list
)
{
int64_t
tid
=
taosGetSelfPthreadId
();
int
i
=
0
;
int
32_t
i
=
0
;
while
(
atomic_val_compare_exchange_64
(
&
(
list
->
lockedBy
),
0
,
tid
)
!=
0
)
{
if
(
++
i
%
1000
==
0
)
{
sched_yield
();
...
...
@@ -322,7 +321,7 @@ static void addToExpired(tmr_obj_t* head) {
}
}
static
uintptr_t
doStartTimer
(
tmr_obj_t
*
timer
,
TAOS_TMR_CALLBACK
fp
,
int
mseconds
,
void
*
param
,
tmr_ctrl_t
*
ctrl
)
{
static
uintptr_t
doStartTimer
(
tmr_obj_t
*
timer
,
TAOS_TMR_CALLBACK
fp
,
int
32_t
mseconds
,
void
*
param
,
tmr_ctrl_t
*
ctrl
)
{
uintptr_t
id
=
getNextTimerId
();
timer
->
id
=
id
;
timer
->
state
=
TIMER_STATE_WAITING
;
...
...
@@ -346,7 +345,7 @@ static uintptr_t doStartTimer(tmr_obj_t* timer, TAOS_TMR_CALLBACK fp, int msecon
return
id
;
}
tmr_h
taosTmrStart
(
TAOS_TMR_CALLBACK
fp
,
int
mseconds
,
void
*
param
,
void
*
handle
)
{
tmr_h
taosTmrStart
(
TAOS_TMR_CALLBACK
fp
,
int
32_t
mseconds
,
void
*
param
,
void
*
handle
)
{
tmr_ctrl_t
*
ctrl
=
(
tmr_ctrl_t
*
)
handle
;
if
(
ctrl
==
NULL
||
ctrl
->
label
[
0
]
==
0
)
{
return
NULL
;
...
...
@@ -361,10 +360,10 @@ tmr_h taosTmrStart(TAOS_TMR_CALLBACK fp, int mseconds, void* param, void* handle
return
(
tmr_h
)
doStartTimer
(
timer
,
fp
,
mseconds
,
param
,
ctrl
);
}
static
void
taosTimerLoopFunc
(
int
signo
)
{
static
void
taosTimerLoopFunc
(
int
32_t
signo
)
{
int64_t
now
=
taosGetMonotonicMs
();
for
(
int
i
=
0
;
i
<
tListLen
(
wheels
);
i
++
)
{
for
(
int
32_t
i
=
0
;
i
<
tListLen
(
wheels
);
i
++
)
{
// `expried` is a temporary expire list.
// expired timers are first add to this list, then move
// to expired queue as a batch to improve performance.
...
...
@@ -471,7 +470,7 @@ bool taosTmrStopA(tmr_h* timerId) {
return
ret
;
}
bool
taosTmrReset
(
TAOS_TMR_CALLBACK
fp
,
int
mseconds
,
void
*
param
,
void
*
handle
,
tmr_h
*
pTmrId
)
{
bool
taosTmrReset
(
TAOS_TMR_CALLBACK
fp
,
int
32_t
mseconds
,
void
*
param
,
void
*
handle
,
tmr_h
*
pTmrId
)
{
tmr_ctrl_t
*
ctrl
=
(
tmr_ctrl_t
*
)
handle
;
if
(
ctrl
==
NULL
||
ctrl
->
label
[
0
]
==
0
)
{
return
false
;
...
...
@@ -500,7 +499,7 @@ bool taosTmrReset(TAOS_TMR_CALLBACK fp, int mseconds, void* param, void* handle,
// wait until there's no other reference to this timer,
// so that we can reuse this timer safely.
for
(
int
i
=
1
;
atomic_load_8
(
&
timer
->
refCount
)
>
1
;
++
i
)
{
for
(
int
32_t
i
=
1
;
atomic_load_8
(
&
timer
->
refCount
)
>
1
;
++
i
)
{
if
(
i
%
1000
==
0
)
{
sched_yield
();
}
...
...
@@ -532,7 +531,7 @@ static void taosTmrModuleInit(void) {
pthread_mutex_init
(
&
tmrCtrlMutex
,
NULL
);
int64_t
now
=
taosGetMonotonicMs
();
for
(
int
i
=
0
;
i
<
tListLen
(
wheels
);
i
++
)
{
for
(
int
32_t
i
=
0
;
i
<
tListLen
(
wheels
);
i
++
)
{
time_wheel_t
*
wheel
=
wheels
+
i
;
if
(
pthread_mutex_init
(
&
wheel
->
mutex
,
NULL
)
!=
0
)
{
tmrError
(
"failed to create the mutex for wheel, reason:%s"
,
strerror
(
errno
));
...
...
@@ -561,7 +560,7 @@ static void taosTmrModuleInit(void) {
tmrDebug
(
"timer module is initialized, number of threads: %d"
,
taosTmrThreads
);
}
void
*
taosTmrInit
(
int
maxNumOfTmrs
,
int
resolution
,
in
t
longest
,
const
char
*
label
)
{
void
*
taosTmrInit
(
int
32_t
maxNumOfTmrs
,
int32_t
resolution
,
int32_
t
longest
,
const
char
*
label
)
{
const
char
*
ret
=
taosMonotonicInit
();
tmrDebug
(
"ttimer monotonic clock source:%s"
,
ret
);
...
...
@@ -607,7 +606,7 @@ void taosTmrCleanUp(void* handle) {
taosCleanUpScheduler
(
tmrQhandle
);
for
(
int
i
=
0
;
i
<
tListLen
(
wheels
);
i
++
)
{
for
(
int
32_t
i
=
0
;
i
<
tListLen
(
wheels
);
i
++
)
{
time_wheel_t
*
wheel
=
wheels
+
i
;
pthread_mutex_destroy
(
&
wheel
->
mutex
);
free
(
wheel
->
slots
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录