diff options
Diffstat (limited to 'lib/qtime.h')
-rw-r--r-- | lib/qtime.h | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/lib/qtime.h b/lib/qtime.h index 35e1a51b..df486dfd 100644 --- a/lib/qtime.h +++ b/lib/qtime.h @@ -108,6 +108,9 @@ qt_get_monotonic(void) ; /* clock_gettime(CLOCK_MONOTONIC, ...) */ /* OR equivalent using times() */ Inline qtime_mono_t qt_add_monotonic(qtime_t interval) ; /* qt_get_monotonic() + interval */ +Inline time_t qt_get_mono_secs(void) ; + /* clock_gettime(CLOCK_MONOTONIC, ...) */ + /* OR equivalent using times() */ Inline qtime_mono_t /* monotonic time from CLOCK_REALTIME */ qt_realtime2monotonic(qtime_real_t realtime) ; @@ -115,8 +118,8 @@ Inline qtime_real_t /* CLOCK_REALTIME from monotonic time */ qt_monotonic2realtime(qtime_mono_t monotonic) ; /* Function to manufacture a monotonic clock. */ -extern qtime_mono_t -qt_craft_monotonic(void) ; +extern qtime_mono_t qt_craft_monotonic(void) ; +extern time_t qt_craft_mono_secs(void) ; /* These are provided just in case gettimeofday() != CLOCK_REALTIME */ Inline qtime_tod_t @@ -254,6 +257,29 @@ qt_add_monotonic(qtime_t interval) return qt_get_monotonic() + interval; } ; +/* clock_gettime(CLOCK_MONOTONIC, ...) OR qt_craft_monotonic() + * -- returning time_t value + * + * Value returned is in seconds -- for coarser grain timings. + * + * While possibility of error is essentially theoretical, must treat it as a + * FATAL error -- cannot continue with broken time value ! + */ +Inline time_t +qt_get_mono_secs(void) +{ +#ifdef HAVE_CLOCK_MONOTONIC + struct timespec ts ; + + if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) + zabort_errno("clock_gettime failed") ; + + return ts.tv_sec ; +#else + return qt_craft_mono_secs() ; +#endif +} ; + /* gettimeofday(&tv, NULL) -- returning qtime_t value */ Inline qtime_tod_t |