From ec0fcd99133c7f6a4e63830a9cf6674c4abc95bf Mon Sep 17 00:00:00 2001 From: Tom Rondeau <trondeau@vt.edu> Date: Sun, 27 Jun 2010 12:01:17 -0400 Subject: Checking for clock_gettime and timespec defined; use gettimeofday if not, but put it into a timespec structure. --- gr-qtgui/src/lib/highResTimeFunctions.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'gr-qtgui/src') diff --git a/gr-qtgui/src/lib/highResTimeFunctions.h b/gr-qtgui/src/lib/highResTimeFunctions.h index 4a82498b49..dc5e1bb801 100644 --- a/gr-qtgui/src/lib/highResTimeFunctions.h +++ b/gr-qtgui/src/lib/highResTimeFunctions.h @@ -246,6 +246,9 @@ diff_timespec(const struct timespec* t1, } +#ifdef CLOCK_REALTIME +// If we can use clock_gettime, use it; +// otherwise, use gettimeofday static inline void get_highres_clock(struct timespec* ret) { @@ -259,6 +262,29 @@ get_highres_clock(struct timespec* ret) } } +#else + +// Test to see if timespec is defined; if not, define it here +#if !defined __timespec_defined +typedef struct _timespec +{ + long int tv_sec; + long int tv_nsec; +} timespec; +#endif + +// Trick the system into thinking it has an nsec timer +// but only use the low resolution (usec) timer. +static inline void +get_highres_clock(struct timespec* ret) +{ + timeval lowResTime; + gettimeofday(&lowResTime, NULL); + ret->tv_sec = lowResTime.tv_sec; + ret->tv_nsec = lowResTime.tv_usec*1000; +} +#endif + static inline struct timespec get_highres_clock() { -- cgit v1.2.3