From e01ded9e27f41af45e8614860b29164d13c0101e Mon Sep 17 00:00:00 2001 From: Takeshi Nakatani Date: Sun, 7 Feb 2016 07:40:55 +0000 Subject: [PATCH] Fixed codes about clock_gettime for osx --- configure.ac | 3 +++ src/cache.cpp | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/configure.ac b/configure.ac index 70d8c65..449128a 100644 --- a/configure.ac +++ b/configure.ac @@ -228,6 +228,9 @@ dnl ---------------------------------------------- dnl malloc_trim function AC_CHECK_FUNCS([malloc_trim]) +dnl clock_gettime function(osx) +AC_CHECK_FUNCS([clock_gettime]) + dnl ---------------------------------------------- dnl check symbols/macros/enums dnl ---------------------------------------------- diff --git a/src/cache.cpp b/src/cache.cpp index d8f7112..e5b9fc9 100644 --- a/src/cache.cpp +++ b/src/cache.cpp @@ -21,6 +21,9 @@ #include #include #include +#ifndef HAVE_CLOCK_GETTIME +#include +#endif #include #include #include @@ -43,6 +46,23 @@ using namespace std; //------------------------------------------------------------------- // Utility //------------------------------------------------------------------- +#if defined(CLOCK_MONOTONIC_COARSE) +#define CLOCK_MONOTONIC_COARSE 6 +#endif + +#ifndef HAVE_CLOCK_GETTIME +static int clock_gettime(int clk_id, struct timespec* ts) +{ + struct timeval now; + if(0 != gettimeofday(&now, NULL)){ + return -1; + } + ts->tv_sec = now.tv_sec; + ts->tv_nsec = now.tv_usec * 1000; + return 0; +} +#endif + inline void SetStatCacheTime(struct timespec& ts) { if(-1 == clock_gettime(CLOCK_MONOTONIC_COARSE, &ts)){