fix:concurrency conflicts occur when obtaining windows system time
This commit is contained in:
parent
ee97487fe5
commit
81e6a9d906
|
@ -551,17 +551,26 @@ int32_t taosClockGetTime(int clock_id, struct timespec *pTS) {
|
|||
static SYSTEMTIME ss;
|
||||
static LARGE_INTEGER offset;
|
||||
|
||||
ss.wYear = 1970;
|
||||
ss.wMonth = 1;
|
||||
ss.wDay = 1;
|
||||
ss.wHour = 0;
|
||||
ss.wMinute = 0;
|
||||
ss.wSecond = 0;
|
||||
ss.wMilliseconds = 0;
|
||||
SystemTimeToFileTime(&ss, &ff);
|
||||
offset.QuadPart = ff.dwHighDateTime;
|
||||
offset.QuadPart <<= 32;
|
||||
offset.QuadPart |= ff.dwLowDateTime;
|
||||
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.wMonth = 1;
|
||||
ss.wDay = 1;
|
||||
ss.wHour = 0;
|
||||
ss.wMinute = 0;
|
||||
ss.wSecond = 0;
|
||||
ss.wMilliseconds = 0;
|
||||
SystemTimeToFileTime(&ss, &ff);
|
||||
offset.QuadPart = ff.dwHighDateTime;
|
||||
offset.QuadPart <<= 32;
|
||||
offset.QuadPart |= ff.dwLowDateTime;
|
||||
offsetInitFinished = true;
|
||||
} else {
|
||||
while (!offsetInitFinished)
|
||||
; // Ensure initialization is completed.
|
||||
}
|
||||
|
||||
GetSystemTimeAsFileTime(&f);
|
||||
t.QuadPart = f.dwHighDateTime;
|
||||
|
|
Loading…
Reference in New Issue