You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by rg...@apache.org on 2015/06/22 02:18:58 UTC

svn commit: r1686767 - in /zookeeper/trunk: CHANGES.txt src/c/src/zookeeper.c

Author: rgs
Date: Mon Jun 22 00:18:57 2015
New Revision: 1686767

URL: http://svn.apache.org/r1686767
Log:
ZOOKEEPER-2210: clock_gettime is not available in OS X
(Michi Mutsuzaki via rgs)

Modified:
    zookeeper/trunk/CHANGES.txt
    zookeeper/trunk/src/c/src/zookeeper.c

Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1686767&r1=1686766&r2=1686767&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Mon Jun 22 00:18:57 2015
@@ -134,6 +134,9 @@ BUGFIXES:
   ZOOKEEPER-2212: distributed race condition related to QV version
   (Akihiro Suda via rgs)
 
+  ZOOKEEPER-2210: clock_gettime is not available in OS X
+  (Michi Mutsuzaki via rgs)
+
 IMPROVEMENTS:
   ZOOKEEPER-1660 Documentation for Dynamic Reconfiguration (Reed Wanderman-Milne via shralex)  
 

Modified: zookeeper/trunk/src/c/src/zookeeper.c
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/c/src/zookeeper.c?rev=1686767&r1=1686766&r2=1686767&view=diff
==============================================================================
--- zookeeper/trunk/src/c/src/zookeeper.c (original)
+++ zookeeper/trunk/src/c/src/zookeeper.c Mon Jun 22 00:18:57 2015
@@ -63,6 +63,11 @@
 #include <pwd.h>
 #endif
 
+#ifdef __MACH__ // OS X
+#include <mach/clock.h>
+#include <mach/mach.h>
+#endif
+
 #define IF_DEBUG(x) if(logLevel==ZOO_LOG_LEVEL_DEBUG) {x;}
 
 const int ZOOKEEPER_WRITE = 1 << 0;
@@ -273,7 +278,23 @@ void get_system_time(struct timeval *tv)
 {
   int ret;
 
-#ifdef CLOCK_MONOTONIC_RAW
+#ifdef __MACH__ // OS X
+  clock_serv_t cclock;
+  mach_timespec_t mts;
+  ret = host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
+  if (!ret) {
+    ret += clock_get_time(cclock, &mts);
+    ret += mach_port_deallocate(mach_task_self(), cclock);
+    if (!ret) {
+      tv->tv_sec = mts.tv_sec;
+      tv->tv_usec = mts.tv_nsec / 1000;
+    }
+  }
+  if (ret) {
+    // Default to gettimeofday in case of failure.
+    ret = gettimeofday(tv, NULL);
+  }
+#elif CLOCK_MONOTONIC_RAW
   // On Linux, CLOCK_MONOTONIC is affected by ntp slew but CLOCK_MONOTONIC_RAW
   // is not.  We want the non-slewed (constant rate) CLOCK_MONOTONIC_RAW if it
   // is available.