]> granicus.if.org Git - pdns/commitdiff
implement OSX workaround for clock_gettime for delaypipe so at least the tests pass...
authorbert hubert <bert.hubert@netherlabs.nl>
Tue, 16 Jun 2015 09:12:35 +0000 (11:12 +0200)
committerbert hubert <bert.hubert@netherlabs.nl>
Tue, 16 Jun 2015 09:12:57 +0000 (11:12 +0200)
pdns/delaypipe.cc
pdns/delaypipe.hh

index 1b6360083187df15d879184cb78ab27ae81629a9..b2a4e5a2e618928b92cb5f45a536d788b535660e 100644 (file)
@@ -77,11 +77,25 @@ DelayPipe<T>::DelayPipe() : d_thread(&DelayPipe<T>::worker, this)
 {
 }
 
+template<class T>
+void DelayPipe<T>::gettime(struct timespec* ts)
+{
+#ifdef __MACH__  // this is a 'limp home' solution since it doesn't do monotonic time. see http://stackoverflow.com/questions/5167269/clock-gettime-alternative-in-mac-os-x
+  struct timeval tv;
+  gettimeofday(&tv, 0);
+  ts->tv_sec = tv.tv_sec;
+  ts->tv_nsec = tv.tv_usec * 1000;
+#else
+  clock_gettime(CLOCK_MONOTONIC, ts);
+#endif
+}
+
+
 template<class T>
 void DelayPipe<T>::submit(T& t, int msec)
 {
   struct timespec now;
-  clock_gettime(CLOCK_MONOTONIC, &now);
+  gettime(&now);
   now.tv_nsec += msec*1e6;
   while(now.tv_nsec > 1e9) {
     now.tv_sec++;
@@ -119,7 +133,7 @@ void DelayPipe<T>::worker()
     double delay=-1;  // infinite
     struct timespec now;
     if(!d_work.empty()) {
-      clock_gettime(CLOCK_MONOTONIC, &now);
+      gettime(&now);
       delay=1000*tsdelta(d_work.begin()->first, now);
       if(delay < 0) {
        delay=0;   // don't wait - we have work that is late already!
@@ -136,7 +150,7 @@ void DelayPipe<T>::worker()
       else {
        ;
       }
-      clock_gettime(CLOCK_MONOTONIC, &now);
+      gettime(&now);
     }
 
     tscomp cmp;
index 00a515a7f24f00ec3272eea5b52de8e632359bc8..68e6265be2378cda8cc360966e727bb2af2c35fd 100644 (file)
@@ -59,6 +59,7 @@ private:
     }
   };
   std::multimap<struct timespec, T, tscomp> d_work;
+  void gettime(struct timespec* ts);
 };
 
 #include "delaypipe.cc"