提交 fdf860eb 编写于 作者: M Minglei Jin

[TD-2875]<fix>: use monotonic clock source to fix leap-second issue

上级 a9160283
......@@ -3,9 +3,10 @@ PROJECT(TDengine)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/rpc/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/sync/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/rmonotonic/inc)
AUX_SOURCE_DIRECTORY(src SRC)
ADD_LIBRARY(tutil ${SRC})
TARGET_LINK_LIBRARIES(tutil pthread osdetail lz4 z)
TARGET_LINK_LIBRARIES(tutil pthread osdetail lz4 z rmonotonic)
IF (TD_LINUX)
TARGET_LINK_LIBRARIES(tutil m rt)
......
......@@ -18,6 +18,7 @@
#include "tsched.h"
#include "ttimer.h"
#include "tutil.h"
#include "monotonic.h"
extern int8_t tscEmbedded;
......@@ -186,6 +187,10 @@ static void removeTimer(uintptr_t id) {
unlockTimerList(list);
}
static int64_t getMonotonicMs(void) {
return (int64_t) getMonotonicUs() / 1000;
}
static void addToWheel(tmr_obj_t* timer, uint32_t delay) {
timerAddRef(timer);
// select a wheel for the timer, we are not an accurate timer,
......@@ -201,7 +206,7 @@ static void addToWheel(tmr_obj_t* timer, uint32_t delay) {
time_wheel_t* wheel = wheels + timer->wheel;
timer->prev = NULL;
timer->expireAt = taosGetTimestampMs() + delay;
timer->expireAt = getMonotonicMs() + delay;
pthread_mutex_lock(&wheel->mutex);
......@@ -334,7 +339,7 @@ tmr_h taosTmrStart(TAOS_TMR_CALLBACK fp, int mseconds, void* param, void* handle
}
static void taosTimerLoopFunc(int signo) {
int64_t now = taosGetTimestampMs();
int64_t now = getMonotonicMs();
for (int i = 0; i < tListLen(wheels); i++) {
// `expried` is a temporary expire list.
......@@ -501,7 +506,8 @@ static void taosTmrModuleInit(void) {
pthread_mutex_init(&tmrCtrlMutex, NULL);
int64_t now = taosGetTimestampMs();
tmrInfo("ttimer monotonic clock source:%s", monotonicInit());
int64_t now = getMonotonicMs();
for (int i = 0; i < tListLen(wheels); i++) {
time_wheel_t* wheel = wheels + i;
if (pthread_mutex_init(&wheel->mutex, NULL) != 0) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册