From d80e0c1fd3bbf37296e908ef5f421c0678ea14fe Mon Sep 17 00:00:00 2001 From: Jesse McDonald Date: Mon, 9 Nov 2009 09:56:31 -0600 Subject: [PATCH] CLOCK_MONOTONIC and uint64_t aren't entirely portable. --- gc.c | 10 ++++++++-- gc.h | 6 ++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/gc.c b/gc.c index ec0239d..9c84bf4 100644 --- a/gc.c +++ b/gc.c @@ -10,6 +10,12 @@ #include "gc.h" +#if _CLOCK_MONOTONIC +# define TIMING_CLOCK CLOCK_MONOTONIC +#else +# define TIMING_CLOCK CLOCK_REALTIME +#endif + gc_stats_t gc_stats; /* Helper macros to reduce duplication */ @@ -652,7 +658,7 @@ static void _collect_garbage(size_t min_free) #ifndef NO_STATS #ifndef NO_TIMING_STATS struct timespec start_time; - clock_gettime(CLOCK_MONOTONIC, &start_time); + clock_gettime(TIMING_CLOCK, &start_time); #endif gc_stats.total_freed -= gc_free_space(); @@ -705,7 +711,7 @@ static void _collect_garbage(size_t min_free) struct timespec end_time; nsec_t nsec; - clock_gettime(CLOCK_MONOTONIC, &end_time); + clock_gettime(TIMING_CLOCK, &end_time); nsec = (end_time.tv_sec - start_time.tv_sec) * 1000000000LL; nsec += (end_time.tv_nsec - start_time.tv_nsec); diff --git a/gc.h b/gc.h index 72bef08..111546e 100644 --- a/gc.h +++ b/gc.h @@ -114,13 +114,15 @@ typedef struct gc_root struct gc_root *next; } gc_root_t; -typedef uint64_t nsec_t; +/* uint64_t isn't present everywhere */ +typedef unsigned long long nsec_t; +typedef unsigned long long llsize_t; typedef struct gc_stats { int collections; nsec_t total_ns; - uint64_t total_freed; + llsize_t total_freed; size_t high_water; nsec_t max_ns; } gc_stats_t;