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:
parent
d393c00c6c
commit
ee6e39305c
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue