Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
0509aedd
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看板
未验证
提交
0509aedd
编写于
3月 11, 2022
作者:
wafwerar
提交者:
GitHub
3月 11, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #10704 from taosdata/fix/ZhiqiangWang/TD-13771-redefine-timer-api
[TD-13771]<fix>: redefine timer api.
上级
e061e718
aa2e9ada
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
57 addition
and
63 deletion
+57
-63
include/os/osTimer.h
include/os/osTimer.h
+9
-0
source/os/src/osTimer.c
source/os/src/osTimer.c
+48
-63
未找到文件。
include/os/osTimer.h
浏览文件 @
0509aedd
...
...
@@ -20,6 +20,15 @@
extern
"C"
{
#endif
// If the error is in a third-party library, place this header file under the third-party library header file.
#ifndef ALLOW_FORBID_FUNC
#define timer_create TIMER_CREATE_FUNC_TAOS_FORBID
#define timer_settime TIMER_SETTIME_FUNC_TAOS_FORBID
#define timer_delete TIMER_DELETE_FUNC_TAOS_FORBID
#define timeSetEvent TIMESETEVENT_SETTIME_FUNC_TAOS_FORBID
#define timeKillEvent TIMEKILLEVENT_SETTIME_FUNC_TAOS_FORBID
#endif
#define MSECONDS_PER_TICK 5
int32_t
taosInitTimer
(
void
(
*
callback
)(
int32_t
),
int32_t
ms
);
...
...
source/os/src/osTimer.c
浏览文件 @
0509aedd
...
...
@@ -13,15 +13,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define ALLOW_FORBID_FUNC
#define _DEFAULT_SOURCE
#include "os.h"
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
/*
* windows implementation
*/
#include <Mmsystem.h>
#include <Windows.h>
#include <stdint.h>
...
...
@@ -39,24 +35,9 @@ void WINAPI taosWinOnTimer(UINT wTimerID, UINT msg, DWORD_PTR dwUser, DWORD_PTR
}
static
MMRESULT
timerId
;
int
taosInitTimer
(
win_timer_f
callback
,
int
ms
)
{
DWORD_PTR
param
=
*
((
int64_t
*
)
&
callback
);
timerId
=
timeSetEvent
(
ms
,
1
,
(
LPTIMECALLBACK
)
taosWinOnTimer
,
param
,
TIME_PERIODIC
);
if
(
timerId
==
0
)
{
return
-
1
;
}
return
0
;
}
void
taosUninitTimer
()
{
timeKillEvent
(
timerId
);
}
#elif defined(_TD_DARWIN_64)
/*
* darwin implementation
*/
#include <sys/event.h>
#include <sys/syscall.h>
#include <unistd.h>
...
...
@@ -88,53 +69,12 @@ static void* timer_routine(void* arg) {
return
NULL
;
}
int
taosInitTimer
(
void
(
*
callback
)(
int
),
int
ms
)
{
int
r
=
0
;
timer_kq
=
-
1
;
timer_stop
=
0
;
timer_ms
=
ms
;
timer_callback
=
callback
;
timer_kq
=
kqueue
();
if
(
timer_kq
==
-
1
)
{
fprintf
(
stderr
,
"==%s[%d]%s()==failed to create timer kq
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
);
// since no caller of this func checks the return value for the moment
abort
();
}
r
=
pthread_create
(
&
timer_thread
,
NULL
,
timer_routine
,
NULL
);
if
(
r
)
{
fprintf
(
stderr
,
"==%s[%d]%s()==failed to create timer thread
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
);
// since no caller of this func checks the return value for the moment
abort
();
}
return
0
;
}
void
taosUninitTimer
()
{
int
r
=
0
;
timer_stop
=
1
;
r
=
pthread_join
(
timer_thread
,
NULL
);
if
(
r
)
{
fprintf
(
stderr
,
"==%s[%d]%s()==failed to join timer thread
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
);
// since no caller of this func checks the return value for the moment
abort
();
}
close
(
timer_kq
);
timer_kq
=
-
1
;
}
void
taos_block_sigalrm
(
void
)
{
// we don't know if there's any specific API for SIGALRM to deliver to specific thread
// this implementation relies on kqueue rather than SIGALRM
}
#else
/*
* linux implementation
*/
#include <sys/syscall.h>
#include <unistd.h>
...
...
@@ -200,8 +140,39 @@ static void * taosProcessAlarmSignal(void *tharg) {
return
NULL
;
}
#endif
int
taosInitTimer
(
void
(
*
callback
)(
int
),
int
ms
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
DWORD_PTR
param
=
*
((
int64_t
*
)
&
callback
);
timerId
=
timeSetEvent
(
ms
,
1
,
(
LPTIMECALLBACK
)
taosWinOnTimer
,
param
,
TIME_PERIODIC
);
if
(
timerId
==
0
)
{
return
-
1
;
}
return
0
;
#elif defined(_TD_DARWIN_64)
int
r
=
0
;
timer_kq
=
-
1
;
timer_stop
=
0
;
timer_ms
=
ms
;
timer_callback
=
callback
;
timer_kq
=
kqueue
();
if
(
timer_kq
==
-
1
)
{
fprintf
(
stderr
,
"==%s[%d]%s()==failed to create timer kq
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
);
// since no caller of this func checks the return value for the moment
abort
();
}
r
=
pthread_create
(
&
timer_thread
,
NULL
,
timer_routine
,
NULL
);
if
(
r
)
{
fprintf
(
stderr
,
"==%s[%d]%s()==failed to create timer thread
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
);
// since no caller of this func checks the return value for the moment
abort
();
}
return
0
;
#else
stopTimer
=
false
;
pthread_attr_t
tattr
;
pthread_attr_init
(
&
tattr
);
...
...
@@ -215,13 +186,29 @@ int taosInitTimer(void (*callback)(int), int ms) {
}
return
0
;
#endif
}
void
taosUninitTimer
()
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
timeKillEvent
(
timerId
);
#elif defined(_TD_DARWIN_64)
int
r
=
0
;
timer_stop
=
1
;
r
=
pthread_join
(
timer_thread
,
NULL
);
if
(
r
)
{
fprintf
(
stderr
,
"==%s[%d]%s()==failed to join timer thread
\n
"
,
taosDirEntryBaseName
(
__FILE__
),
__LINE__
,
__func__
);
// since no caller of this func checks the return value for the moment
abort
();
}
close
(
timer_kq
);
timer_kq
=
-
1
;
#else
stopTimer
=
true
;
// printf("join timer thread:0x%08" PRIx64, taosGetPthreadId(timerThread));
pthread_join
(
timerThread
,
NULL
);
#endif
}
int64_t
taosGetMonotonicMs
()
{
...
...
@@ -239,5 +226,3 @@ const char *taosMonotonicInit() {
return
NULL
;
#endif
}
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录