Checking for clock_gettime and timespec defined; use gettimeofday if not, but put...
authorTom Rondeau <trondeau@vt.edu>
Sun, 27 Jun 2010 16:01:17 +0000 (12:01 -0400)
committerTom Rondeau <trondeau@vt.edu>
Sun, 27 Jun 2010 16:01:17 +0000 (12:01 -0400)
gr-qtgui/src/lib/highResTimeFunctions.h

index 4a82498b49220d71655acdcf3dc409fb14aeef73..dc5e1bb801068ffdb0423e0541c4c43c2aa38932 100644 (file)
@@ -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()
 {