Fix bug in time_util::time_ns, add a fixed bit version

This commit is contained in:
2025-12-18 16:18:43 +08:00
parent f7e2f6773f
commit 9dfedd6187
2 changed files with 18 additions and 1 deletions

View File

@@ -73,7 +73,7 @@ size_t time_util::time_ns() {
FILETIME ft;
GetSystemTimeAsFileTime(&ft);
size_t t = ((size_t)ft.dwHighDateTime << 32) | (size_t)ft.dwLowDateTime;
return t;
return t * 100;
#elif HAVE_CLOCK_GETTIME
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
@@ -83,6 +83,21 @@ size_t time_util::time_ns() {
#endif
}
int64_t time_util::time_ns64() {
#if _WIN32
FILETIME ft;
GetSystemTimeAsFileTime(&ft);
int64_t t = ((int64_t)ft.dwHighDateTime << 32) | (int64_t)ft.dwLowDateTime;
return t * 100;
#elif HAVE_CLOCK_GETTIME
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
return ts.tv_sec * 1000000000LL + ts.tv_nsec;
#else
return (int64_t)time(NULL) * 1000000000LL;
#endif
}
size_t time_time_ns() {
return time_util::time_ns();
}

View File

@@ -4,6 +4,7 @@
#if _WIN32
#include <Windows.h>
#endif
#include <stdint.h>
#if __cplusplus
@@ -20,6 +21,7 @@ namespace time_util {
long get_timezone();
time_t timegm(struct tm* tm);
size_t time_ns();
int64_t time_ns64();
int mssleep(unsigned int ms);
}