Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
b834fb6f
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看板
提交
b834fb6f
编写于
1月 29, 2021
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
msvclibx/clock_gettime: add CLOCK_MONOTONIC to msvclibx
上级
711d3dc7
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
55 addition
and
79 deletion
+55
-79
deps/MsvcLibX/include/msvcTime.h
deps/MsvcLibX/include/msvcTime.h
+1
-0
deps/MsvcLibX/src/clock_gettime.c
deps/MsvcLibX/src/clock_gettime.c
+46
-5
deps/rmonotonic/CMakeLists.txt
deps/rmonotonic/CMakeLists.txt
+1
-0
deps/rmonotonic/inc/monotonic.h
deps/rmonotonic/inc/monotonic.h
+4
-0
deps/rmonotonic/src/clock_gettime_win.c
deps/rmonotonic/src/clock_gettime_win.c
+0
-72
deps/rmonotonic/src/monotonic.c
deps/rmonotonic/src/monotonic.c
+3
-2
未找到文件。
deps/MsvcLibX/include/msvcTime.h
浏览文件 @
b834fb6f
...
...
@@ -38,6 +38,7 @@
typedef
int
clockid_t
;
/* Supported values for clockid_t */
#define CLOCK_REALTIME 0
#define CLOCK_MONOTONIC 1
int
clock_gettime
(
clockid_t
clock_id
,
struct
timespec
*
tp
);
...
...
deps/MsvcLibX/src/clock_gettime.c
浏览文件 @
b834fb6f
...
...
@@ -34,15 +34,56 @@
#include "msvcTime.h"
#include "sys/msvcStat.h"
/* For MsvcLibX's Filetime2Timespec */
int
clock_gettime
(
clockid_t
clock_id
,
struct
timespec
*
pTS
)
{
FILETIME
ft
;
if
(
clock_id
!=
CLOCK_REALTIME
)
{
errno
=
EINVAL
;
return
-
1
;
#define MS_PER_SEC 1000ULL // MS = milliseconds
#define US_PER_MS 1000ULL // US = microseconds
#define HNS_PER_US 10ULL // HNS = hundred-nanoseconds (e.g., 1 hns = 100 ns)
#define NS_PER_US 1000ULL
#define HNS_PER_SEC (MS_PER_SEC * US_PER_MS * HNS_PER_US)
#define NS_PER_HNS (100ULL) // NS = nanoseconds
#define NS_PER_SEC (MS_PER_SEC * US_PER_MS * NS_PER_US)
int
clock_gettime_monotonic
(
struct
timespec
*
tv
)
{
static
LARGE_INTEGER
ticksPerSec
;
LARGE_INTEGER
ticks
;
double
seconds
;
if
(
!
ticksPerSec
.
QuadPart
)
{
QueryPerformanceFrequency
(
&
ticksPerSec
);
if
(
!
ticksPerSec
.
QuadPart
)
{
errno
=
ENOTSUP
;
return
-
1
;
}
}
QueryPerformanceCounter
(
&
ticks
);
seconds
=
(
double
)
ticks
.
QuadPart
/
(
double
)
ticksPerSec
.
QuadPart
;
tv
->
tv_sec
=
(
time_t
)
seconds
;
tv
->
tv_nsec
=
(
long
)((
ULONGLONG
)(
seconds
*
NS_PER_SEC
)
%
NS_PER_SEC
);
return
0
;
}
int
clock_gettime_realtime
(
struct
timespec
*
pTS
)
{
FILETIME
ft
;
GetSystemTimeAsFileTime
(
&
ft
);
Filetime2Timespec
(
&
ft
,
pTS
);
return
0
;
}
int
clock_gettime
(
clockid_t
clock_id
,
struct
timespec
*
pTS
)
{
if
(
clock_id
==
CLOCK_MONOTONIC
)
{
return
clock_gettime_monotonic
(
pTS
);
}
else
if
(
clock_id
==
CLOCK_REALTIME
)
{
return
clock_gettime_realtime
(
pTS
);
}
errno
=
ENOTSUP
;
return
-
1
;
}
#endif
/* defined(_WIN32) */
deps/rmonotonic/CMakeLists.txt
浏览文件 @
b834fb6f
...
...
@@ -4,3 +4,4 @@ add_definitions(-DUSE_PROCESSOR_CLOCK)
ADD_LIBRARY
(
rmonotonic
${
SOURCE_LIST
}
)
TARGET_INCLUDE_DIRECTORIES
(
rmonotonic PUBLIC
${
CMAKE_CURRENT_SOURCE_DIR
}
/inc
)
TARGET_LINK_LIBRARIES
(
rmonotonic MsvcLibXw
)
deps/rmonotonic/inc/monotonic.h
浏览文件 @
b834fb6f
...
...
@@ -15,6 +15,10 @@
#include <stdint.h>
//#include <unistd.h>
#if defined(_WIN32) || defined(_WIN64)
#define inline
#endif
/* A counter in micro-seconds. The 'monotime' type is provided for variables
* holding a monotonic time. This will help distinguish & document that the
* variable is associated with the monotonic clock and should not be confused
...
...
deps/rmonotonic/src/clock_gettime_win.c
已删除
100644 → 0
浏览文件 @
711d3dc7
#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#include <time.h>
#define MS_PER_SEC 1000ULL // MS = milliseconds
#define US_PER_MS 1000ULL // US = microseconds
#define HNS_PER_US 10ULL // HNS = hundred-nanoseconds (e.g., 1 hns = 100 ns)
#define NS_PER_US 1000ULL
#define HNS_PER_SEC (MS_PER_SEC * US_PER_MS * HNS_PER_US)
#define NS_PER_HNS (100ULL) // NS = nanoseconds
#define NS_PER_SEC (MS_PER_SEC * US_PER_MS * NS_PER_US)
int
clock_gettime_monotonic
(
struct
timespec
*
tv
)
{
static
LARGE_INTEGER
ticksPerSec
;
LARGE_INTEGER
ticks
;
double
seconds
;
if
(
!
ticksPerSec
.
QuadPart
)
{
QueryPerformanceFrequency
(
&
ticksPerSec
);
if
(
!
ticksPerSec
.
QuadPart
)
{
errno
=
ENOTSUP
;
return
-
1
;
}
}
QueryPerformanceCounter
(
&
ticks
);
seconds
=
(
double
)
ticks
.
QuadPart
/
(
double
)
ticksPerSec
.
QuadPart
;
tv
->
tv_sec
=
(
time_t
)
seconds
;
tv
->
tv_nsec
=
(
long
)((
ULONGLONG
)(
seconds
*
NS_PER_SEC
)
%
NS_PER_SEC
);
return
0
;
}
int
clock_gettime_realtime
(
struct
timespec
*
tv
)
{
FILETIME
ft
;
ULARGE_INTEGER
hnsTime
;
GetSystemTimeAsFileTime
(
&
ft
);
hnsTime
.
LowPart
=
ft
.
dwLowDateTime
;
hnsTime
.
HighPart
=
ft
.
dwHighDateTime
;
// To get POSIX Epoch as baseline, subtract the number of hns intervals from Jan 1, 1601 to Jan 1, 1970.
hnsTime
.
QuadPart
-=
(
11644473600ULL
*
HNS_PER_SEC
);
// modulus by hns intervals per second first, then convert to ns, as not to lose resolution
tv
->
tv_nsec
=
(
long
)
((
hnsTime
.
QuadPart
%
HNS_PER_SEC
)
*
NS_PER_HNS
);
tv
->
tv_sec
=
(
long
)
(
hnsTime
.
QuadPart
/
HNS_PER_SEC
);
return
0
;
}
int
clock_gettime
(
clockid_t
type
,
struct
timespec
*
tp
)
{
if
(
type
==
CLOCK_MONOTONIC
)
{
return
clock_gettime_monotonic
(
tp
);
}
else
if
(
type
==
CLOCK_REALTIME
)
{
return
clock_gettime_realtime
(
tp
);
}
errno
=
ENOTSUP
;
return
-
1
;
}
#endif
deps/rmonotonic/src/monotonic.c
浏览文件 @
b834fb6f
...
...
@@ -7,6 +7,8 @@
#undef NDEBUG
#include <assert.h>
#include "msvcTime.h"
#include "msvcStdio.h"
/* The function pointer for clock retrieval. */
monotime
(
*
getMonotonicUs
)(
void
)
=
NULL
;
...
...
@@ -129,8 +131,7 @@ static void monotonicInit_aarch64() {
}
#endif
static
monotime
getMonotonicUs_posix
()
{
static
monotime
getMonotonicUs_posix
(
void
)
{
/* clock_gettime() is specified in POSIX.1b (1993). Even so, some systems
* did not support this until much later. CLOCK_MONOTONIC is technically
* optional and may not be supported - but it appears to be universal.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录