From 839505966bdd8ffbd9f730aef55d0dccfa35f45c Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Sun, 24 Jan 2016 18:19:28 -0500 Subject: [PATCH] time: Make ceph_time clocks work under BSD 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 --- src/common/ceph_time.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/common/ceph_time.h b/src/common/ceph_time.h index a634e7fec554..34847668b851 100644 --- a/src/common/ceph_time.h +++ b/src/common/ceph_time.h @@ -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)); } }; -- 2.47.3