ソースを参照

Update time.c

blueloveTH 3 ヶ月 前
コミット
d03610071a
1 ファイル変更16 行追加2 行削除
  1. 16 2
      src/modules/time.c

+ 16 - 2
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; }