From cc43cfbb418ab7b4b2786123d33ede23b3cb5ea3 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 14 Jan 2011 09:07:57 +0000 Subject: another workaround for systems with broken CLOCK_MONOTONIC This should also detect cases where CLOCK_MONOTONIC is available at build but not at runtime. --- ext/clogger_ext/broken_system_compat.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'ext/clogger_ext/broken_system_compat.h') diff --git a/ext/clogger_ext/broken_system_compat.h b/ext/clogger_ext/broken_system_compat.h index f58307e..ec635b1 100644 --- a/ext/clogger_ext/broken_system_compat.h +++ b/ext/clogger_ext/broken_system_compat.h @@ -3,11 +3,15 @@ * without clock_gettime() or CLOCK_MONOTONIC */ +#ifndef HAVE_TYPE_CLOCKID_T +typedef clockid_t int; +#endif + #ifndef HAVE_CLOCK_GETTIME # ifndef CLOCK_REALTIME # define CLOCK_REALTIME 0 /* whatever */ # endif -static int fake_clock_gettime(int clk_id, struct timespec *res) +static int fake_clock_gettime(clockid_t clk_id, struct timespec *res) { struct timeval tv; int r = gettimeofday(&tv, NULL); @@ -21,7 +25,12 @@ static int fake_clock_gettime(int clk_id, struct timespec *res) # define clock_gettime fake_clock_gettime #endif /* broken systems w/o clock_gettime() */ -/* UGH */ -#ifndef _POSIX_MONOTONIC_CLOCK -# define CLOCK_MONOTONIC CLOCK_REALTIME +/* + * UGH + * CLOCK_MONOTONIC is not guaranteed to be a macro, either + */ +#ifndef CLOCK_MONOTONIC +# if (!defined(_POSIX_MONOTONIC_CLOCK) || !defined(HAVE_CLOCK_MONOTONIC)) +# define CLOCK_MONOTONIC CLOCK_REALTIME +# endif #endif -- cgit v1.2.3-24-ge0c7