]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: avoid redefining clock type on Windows 50559/head
authorLucian Petrut <lpetrut@cloudbasesolutions.com>
Thu, 16 Mar 2023 14:25:50 +0000 (14:25 +0000)
committerLucian Petrut <lpetrut@cloudbasesolutions.com>
Fri, 17 Mar 2023 07:38:16 +0000 (07:38 +0000)
mingw >= 8.0.1 defines CLOCK_REALTIME_COARSE, so we'll avoid
overriding it if already set.

Clock precision [1]:

mingw < 8.0.1:
  * CLOCK_REALTIME: ~10-55ms (GetSystemTimeAsFileTime)
mingw >= 8.0.1:
  * CLOCK_REALTIME: <1us (GetSystemTimePreciseAsFileTime)
  * CLOCK_REALTIME_COARSE: ~10-55ms (GetSystemTimeAsFileTime)

* CLOCK_MONOTONIC: <1us if TSC is usable, ~10-55ms otherwise
                   (QueryPerformanceCounter)

[1] https://github.com/mirror/mingw-w64/commit/dcd990ed423381cf35702df9495d44f1979ebe50

Signed-off-by: Lucian Petrut <lpetrut@cloudbasesolutions.com>
src/common/ceph_time.h

index 2d3d1fda010e596751221021626bb8c4516a8661..292fa91ac24b594eb1d3f1420804c754d4fe5e66 100644 (file)
@@ -34,9 +34,22 @@ int clock_gettime(int clk_id, struct timespec *tp);
 #endif
 
 #ifdef _WIN32
-#define CLOCK_REALTIME_COARSE CLOCK_REALTIME
-#define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC
-// MINGW uses the QueryPerformanceCounter API behind the scenes.
+// Clock precision:
+// mingw < 8.0.1:
+//   * CLOCK_REALTIME: ~10-55ms (GetSystemTimeAsFileTime)
+// mingw >= 8.0.1:
+//   * CLOCK_REALTIME: <1us (GetSystemTimePreciseAsFileTime)
+//   * CLOCK_REALTIME_COARSE: ~10-55ms (GetSystemTimeAsFileTime)
+//
+// * CLOCK_MONOTONIC: <1us if TSC is usable, ~10-55ms otherwise
+//                    (QueryPerformanceCounter)
+// https://github.com/mirror/mingw-w64/commit/dcd990ed423381cf35702df9495d44f1979ebe50
+#ifndef CLOCK_REALTIME_COARSE
+  #define CLOCK_REALTIME_COARSE CLOCK_REALTIME
+#endif
+#ifndef CLOCK_MONOTONIC_COARSE
+  #define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC
+#endif
 #endif
 
 struct ceph_timespec;