提交 81e6a9d9 编写于 作者: F facetosea

fix:concurrency conflicts occur when obtaining windows system time

上级 ee97487f
...@@ -551,6 +551,10 @@ int32_t taosClockGetTime(int clock_id, struct timespec *pTS) { ...@@ -551,6 +551,10 @@ int32_t taosClockGetTime(int clock_id, struct timespec *pTS) {
static SYSTEMTIME ss; static SYSTEMTIME ss;
static LARGE_INTEGER offset; static LARGE_INTEGER offset;
static int8_t offsetInit = 0;
static volatile bool offsetInitFinished = false;
int8_t old = atomic_val_compare_exchange_8(&offsetInit, 0, 1);
if (0 == old) {
ss.wYear = 1970; ss.wYear = 1970;
ss.wMonth = 1; ss.wMonth = 1;
ss.wDay = 1; ss.wDay = 1;
...@@ -562,6 +566,11 @@ int32_t taosClockGetTime(int clock_id, struct timespec *pTS) { ...@@ -562,6 +566,11 @@ int32_t taosClockGetTime(int clock_id, struct timespec *pTS) {
offset.QuadPart = ff.dwHighDateTime; offset.QuadPart = ff.dwHighDateTime;
offset.QuadPart <<= 32; offset.QuadPart <<= 32;
offset.QuadPart |= ff.dwLowDateTime; offset.QuadPart |= ff.dwLowDateTime;
offsetInitFinished = true;
} else {
while (!offsetInitFinished)
; // Ensure initialization is completed.
}
GetSystemTimeAsFileTime(&f); GetSystemTimeAsFileTime(&f);
t.QuadPart = f.dwHighDateTime; t.QuadPart = f.dwHighDateTime;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册