]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
time: make ceph_time clocks work under OSX
authorYan, Zheng <zyan@redhat.com>
Mon, 15 Feb 2016 02:47:20 +0000 (10:47 +0800)
committerYan, Zheng <zyan@redhat.com>
Mon, 18 Jul 2016 03:08:48 +0000 (11:08 +0800)
Signed-off-by: Yan, Zheng <zyan@redhat.com>
src/common/ceph_time.cc
src/common/ceph_time.h

index d7b512b0ac8a785886bcda155210c8c009791ed6..742481d9f4188a2f0b54c66345c2e70105f04bfa 100644 (file)
 #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 {
index e5197ba96cae66269e64ecceb4c540a1dbcb3d61..5fb867bc83e2a80fc11e27011be47b6af148d03b 100644 (file)
 
 #include "include/encoding.h"
 
+#if defined(DARWIN)
+#include <sys/_types/_timespec.h>
+#include <mach/mach.h>
+#include <mach/clock.h>
+
+#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;