CLOCK_MONOTONIC and uint64_t aren't entirely portable.

This commit is contained in:
Jesse D. McDonald 2009-11-09 09:56:31 -06:00
parent cec35b4d7c
commit d80e0c1fd3
2 changed files with 12 additions and 4 deletions

10
gc.c
View File

@ -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);

6
gc.h
View File

@ -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;