]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
time: Make ceph_time clocks work under BSD 7340/head
authorAdam C. Emerson <aemerson@redhat.com>
Sun, 24 Jan 2016 23:19:28 +0000 (18:19 -0500)
committerAdam C. Emerson <aemerson@redhat.com>
Mon, 25 Jan 2016 20:45:22 +0000 (15:45 -0500)
Linux's naming things _COARSE is non-standard. Other systems name them other
non-standard things. BSD names them _FAST.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/common/ceph_time.h

index a634e7fec554bf7248356c807161d685a0671015..34847668b8513d0bf418416ad1131180ae4501a0 100644 (file)
@@ -151,7 +151,18 @@ namespace ceph {
 
       static time_point now() noexcept {
        struct timespec ts;
+#if defined(CLOCK_REALTIME_COARSE)
+       // Linux systems have _COARSE clocks.
        clock_gettime(CLOCK_REALTIME_COARSE, &ts);
+#elif defined(CLOCK_REALTIME_FAST)
+       // BSD systems have _FAST clocks.
+       clock_gettime(CLOCK_REALTIME_FAST, &ts);
+#else
+       // And if we find neither, you may wish to consult your system's
+       // documentation.
+#warning Falling back to CLOCK_REALTIME, may be slow.
+       clock_gettime(CLOCK_REALTIME, &ts);
+#endif
        return from_timespec(ts);
       }
       static time_point now(const CephContext* cct) noexcept;
@@ -233,7 +244,18 @@ namespace ceph {
 
       static time_point now() noexcept {
        struct timespec ts;
+#if defined(CLOCK_MONOTONIC_COARSE)
+       // Linux systems have _COARSE clocks.
        clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
+#elif defined(CLOCK_MONOTONIC_FAST)
+       // BSD systems have _FAST clocks.
+       clock_gettime(CLOCK_MONOTONIC_FAST, &ts);
+#else
+       // And if we find neither, you may wish to consult your system's
+       // documentation.
+#warning Falling back to CLOCK_MONOTONIC, may be slow.
+       clock_gettime(CLOCK_MONOTONIC, &ts);
+#endif
        return time_point(seconds(ts.tv_sec) + nanoseconds(ts.tv_nsec));
       }
     };