From: Adam C. Emerson Date: Sun, 24 Jan 2016 23:19:28 +0000 (-0500) Subject: time: Make ceph_time clocks work under BSD X-Git-Tag: v10.0.4~132^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=839505966bdd8ffbd9f730aef55d0dccfa35f45c;p=ceph.git 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 --- diff --git a/src/common/ceph_time.h b/src/common/ceph_time.h index a634e7fec55..34847668b85 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)); } };