include: add indirect monotonic clock id specifier

Avoid repeated ifdef checks in code by adding a project specific
preprocessor definition.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2019-01-07 21:31:34 +00:00
parent d393c00c6c
commit ee6e39305c
No known key found for this signature in database
GPG Key ID: 0D46FEF7E61DBB46
2 changed files with 7 additions and 5 deletions

View File

@ -1,6 +1,12 @@
#ifndef UTIL_LINUX_MONOTONIC_H
#define UTIL_LINUX_MONOTONIC_H
# ifdef CLOCK_MONOTONIC_RAW
# define UL_CLOCK_MONOTONIC CLOCK_MONOTONIC_RAW
# else
# define UL_CLOCK_MONOTONIC CLOCK_MONOTONIC
# endif
#include <sys/time.h>
extern int get_boot_time(struct timeval *boot_time);

View File

@ -52,12 +52,8 @@ int gettime_monotonic(struct timeval *tv)
int ret;
struct timespec ts;
# ifdef CLOCK_MONOTONIC_RAW
/* Linux specific, can't slew */
if (!(ret = clock_gettime(CLOCK_MONOTONIC_RAW, &ts))) {
# else
if (!(ret = clock_gettime(CLOCK_MONOTONIC, &ts))) {
# endif
if (!(ret = clock_gettime(UL_CLOCK_MONOTONIC, &ts))) {
tv->tv_sec = ts.tv_sec;
tv->tv_usec = ts.tv_nsec / 1000;
}