From 8f4a3c169c720e3596f836d0a82d0e8f87d2f6ff Mon Sep 17 00:00:00 2001 From: bert hubert Date: Tue, 16 Jun 2015 11:12:35 +0200 Subject: [PATCH] implement OSX workaround for clock_gettime for delaypipe so at least the tests pass and compile --- pdns/delaypipe.cc | 20 +++++++++++++++++--- pdns/delaypipe.hh | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/pdns/delaypipe.cc b/pdns/delaypipe.cc index 1b6360083..b2a4e5a2e 100644 --- a/pdns/delaypipe.cc +++ b/pdns/delaypipe.cc @@ -77,11 +77,25 @@ DelayPipe::DelayPipe() : d_thread(&DelayPipe::worker, this) { } +template +void DelayPipe::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 void DelayPipe::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::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::worker() else { ; } - clock_gettime(CLOCK_MONOTONIC, &now); + gettime(&now); } tscomp cmp; diff --git a/pdns/delaypipe.hh b/pdns/delaypipe.hh index 00a515a7f..68e6265be 100644 --- a/pdns/delaypipe.hh +++ b/pdns/delaypipe.hh @@ -59,6 +59,7 @@ private: } }; std::multimap d_work; + void gettime(struct timespec* ts); }; #include "delaypipe.cc" -- 2.40.0