Numerous fixes related to compiling for mingw
[m6w6/libmemcached] / libtest / timer.hpp
index eac5194036300a533dfabfbf14f4fd4f9a8adc61..73de26c6ac2361168cdf7974180cd32d4fa3c5e1 100644 (file)
@@ -44,7 +44,6 @@
 #  include <mach/clock.h>
 #  include <mach/mach.h>
 #else
-#  include <time.h>
 #  include <sys/time.h>
 #endif
 
@@ -115,7 +114,9 @@ public:
 private:
   void _time(struct timespec& ts)
   {
-#ifdef __MACH__ // OSX lacks clock_gettime()
+#if defined(HAVE_CLOCK_GETTIME) && HAVE_CLOCK_GETTIME
+    clock_gettime(CLOCK_REALTIME, &ts);
+#elif defined(__MACH__) && __MACH__ // OSX lacks clock_gettime()
     clock_serv_t _clock_serv;
     mach_timespec_t _mach_timespec;
     host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &_clock_serv);
@@ -123,24 +124,7 @@ private:
     mach_port_deallocate(mach_task_self(), _clock_serv);
     ts.tv_sec= _mach_timespec.tv_sec;
     ts.tv_nsec= _mach_timespec.tv_nsec;
-#elif defined(HAVE_CLOCK_GETTIME) && HAVE_CLOCK_GETTIME
-    int ret;
-    do
-    {
-      ret= clock_gettime(CLOCK_REALTIME, &ts);
-    } while (ret == -1);
-#elif defined(HAVE_GETTIMEOFDAY) && HAVE_GETTIMEOFDAY
-    struct timeval tv;
-    int ret;
-    do 
-    {
-      ret= gettimeofday(&tv, NULL)
-    } while (ret == -1);
-    /* Convert from timeval to timespec */
-    ts.tv_sec= tv.tv_sec;
-    ts.tv_nsec= tv.tv_usec * 1000;
 #else
-    memset(&ts, 0, sizeof(struct timespec));
 #endif
   }