From d03610071adf3db08244c2ec8cc8bbf69ba68ea3 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Wed, 26 Nov 2025 23:13:54 +0800 Subject: [PATCH] Update time.c --- src/modules/time.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/modules/time.c b/src/modules/time.c index bffabffc..ee460a40 100644 --- a/src/modules/time.c +++ b/src/modules/time.c @@ -16,7 +16,20 @@ #define NANOS_PER_SEC 1000000000 #ifndef __circle__ + int64_t time_ns() { +#ifdef _WIN32 + FILETIME system_time; + ULARGE_INTEGER large; + + GetSystemTimePreciseAsFileTime(&system_time); + large.u.LowPart = system_time.dwLowDateTime; + large.u.HighPart = system_time.dwHighDateTime; + /* 11,644,473,600,000,000,000: number of nanoseconds between + the 1st january 1601 and the 1st january 1970 (369 years + 89 leap + days). */ + return (large.QuadPart - 116444736000000000) * 100; +#else struct timespec tms; #ifdef CLOCK_REALTIME clock_gettime(CLOCK_REALTIME, &tms); @@ -29,6 +42,7 @@ int64_t time_ns() { /* Add full nanoseconds */ nanos += tms.tv_nsec; return nanos; +#endif } int64_t time_monotonic_ns() { @@ -40,8 +54,7 @@ int64_t time_monotonic_ns() { if(freq.QuadPart == 0) QueryPerformanceFrequency(&freq); /* Convert ticks to nanoseconds */ return (ticksll * NANOS_PER_SEC) / freq.QuadPart; -#endif - +#else struct timespec tms; #ifdef CLOCK_MONOTONIC clock_gettime(CLOCK_MONOTONIC, &tms); @@ -54,6 +67,7 @@ int64_t time_monotonic_ns() { /* Add full nanoseconds */ nanos += tms.tv_nsec; return nanos; +#endif } #else int64_t time_ns() { return 0; }