From: Yan, Zheng Date: Mon, 15 Feb 2016 02:47:20 +0000 (+0800) Subject: time: make ceph_time clocks work under OSX X-Git-Tag: ses5-milestone5~283^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=23f9505ec208a9199918169aadda510d9a86f6e7;p=ceph.git time: make ceph_time clocks work under OSX Signed-off-by: Yan, Zheng --- diff --git a/src/common/ceph_time.cc b/src/common/ceph_time.cc index d7b512b0ac8..742481d9f41 100644 --- a/src/common/ceph_time.cc +++ b/src/common/ceph_time.cc @@ -19,6 +19,32 @@ #include "ceph_time.h" #include "config.h" +#if defined(DARWIN) +int clock_gettime(int clk_id, struct timespec *tp) +{ + if (clk_id == CALENDAR_CLOCK) { + // gettimeofday is much faster than clock_get_time + struct timeval now; + int ret = gettimeofday(&now, NULL); + if (ret) + return ret; + tp->tv_sec = now.tv_sec; + tp->tv_nsec = now.tv_usec * 1000L; + } else { + clock_serv_t cclock; + mach_timespec_t mts; + + host_get_clock_service(mach_host_self(), clk_id, &cclock); + clock_get_time(cclock, &mts); + mach_port_deallocate(mach_task_self(), cclock); + + tp->tv_sec = mts.tv_sec; + tp->tv_nsec = mts.tv_nsec; + } + return 0; +} +#endif + namespace ceph { namespace time_detail { real_clock::time_point real_clock::now(const CephContext* cct) noexcept { diff --git a/src/common/ceph_time.h b/src/common/ceph_time.h index e5197ba96ca..5fb867bc83e 100644 --- a/src/common/ceph_time.h +++ b/src/common/ceph_time.h @@ -20,6 +20,19 @@ #include "include/encoding.h" +#if defined(DARWIN) +#include +#include +#include + +#define CLOCK_REALTIME CALENDAR_CLOCK +#define CLOCK_MONOTONIC SYSTEM_CLOCK +#define CLOCK_REALTIME_COARSE CLOCK_REALTIME +#define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC + +int clock_gettime(int clk_id, struct timespec *tp); +#endif + class CephContext; struct ceph_timespec;