From 286a6301f88c3045abb0aa61e92073354f5f6de8 Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Fri, 7 Aug 2020 15:08:45 +0800 Subject: [PATCH] Try to clean up the compat stuff a bit --- compat/clock_gettime/clock_gettime.c | 6 +++-- compat/clock_gettime/clock_gettime.h | 29 ----------------------- compat/clock_nanosleep/clock_nanosleep.c | 5 +--- compat/clock_nanosleep/clock_nanosleep.h | 30 ------------------------ compat/compat.h | 24 +++++++++++++++++++ 5 files changed, 29 insertions(+), 65 deletions(-) diff --git a/compat/clock_gettime/clock_gettime.c b/compat/clock_gettime/clock_gettime.c index 372ff2e..cd2f824 100644 --- a/compat/clock_gettime/clock_gettime.c +++ b/compat/clock_gettime/clock_gettime.c @@ -58,8 +58,8 @@ * */ - -#include "clock_gettime.h" +#include "../compat.h" +#include #include // for clock_get_time #include // for mach_timespec_t, CALENDAR_CLOCK, etc #include // for KERN_SUCCESS, kern_return_t @@ -70,6 +70,8 @@ #include // for EINVAL, errno #include // for getpid +static mach_timebase_info_data_t __clock_gettime_inf; + int clock_gettime(clockid_t clk_id, struct timespec *tp) { kern_return_t ret; diff --git a/compat/clock_gettime/clock_gettime.h b/compat/clock_gettime/clock_gettime.h index 3c4c29b..a7dc7ae 100644 --- a/compat/clock_gettime/clock_gettime.h +++ b/compat/clock_gettime/clock_gettime.h @@ -1,35 +1,6 @@ #ifndef CLOCK_GETTIME_H #define CLOCK_GETTIME_H -#include // Apple-only, but this isn't inclued on other BSDs - -#ifdef __OpenBSD__ -#ifdef _CLOCKID_T_DEFINED_ -#define CLOCKID_T -#endif -#endif - -#ifdef __APPLE__ -#ifdef CLOCK_MONOTONIC -#define CLOCKID_T -#endif -#endif - -#ifndef CLOCKID_T -#define CLOCKID_T -typedef enum -{ - CLOCK_REALTIME, - CLOCK_MONOTONIC, - CLOCK_PROCESS_CPUTIME_ID, - CLOCK_THREAD_CPUTIME_ID -} clockid_t; -#endif // ifndef CLOCKID_T - -struct timespec; - -static mach_timebase_info_data_t __clock_gettime_inf; - int clock_gettime(clockid_t clk_id, struct timespec *tp); #endif // CLOCK_GETTIME_H diff --git a/compat/clock_nanosleep/clock_nanosleep.c b/compat/clock_nanosleep/clock_nanosleep.c index f6e3d84..0eeb359 100644 --- a/compat/clock_nanosleep/clock_nanosleep.c +++ b/compat/clock_nanosleep/clock_nanosleep.c @@ -22,10 +22,7 @@ #include // for errno, EINVAL #include // for nanosleep, NULL -#include "clock_nanosleep.h" -#ifdef MISSING_GETTIME -#include "../clock_gettime/clock_gettime.h" // for clock_gettime -#endif +#include "../compat.h" int clock_nanosleep(clockid_t id, int flags, const struct timespec *ts, struct timespec *ots) { diff --git a/compat/clock_nanosleep/clock_nanosleep.h b/compat/clock_nanosleep/clock_nanosleep.h index 34eb801..5e1f0c3 100644 --- a/compat/clock_nanosleep/clock_nanosleep.h +++ b/compat/clock_nanosleep/clock_nanosleep.h @@ -1,36 +1,6 @@ #ifndef CLOCK_NANOSLEEP_H #define CLOCK_NANOSLEEP_H -#ifdef __OpenBSD__ -#ifdef _CLOCKID_T_DEFINED_ -#define CLOCKID_T -#endif -#endif - -#ifdef __APPLE__ -#ifdef CLOCK_MONOTONIC -#define CLOCKID_T -#endif -#endif - -#ifndef CLOCKID_T -#define CLOCKID_T -typedef enum -{ - CLOCK_REALTIME, - CLOCK_MONOTONIC, - CLOCK_PROCESS_CPUTIME_ID, - CLOCK_THREAD_CPUTIME_ID -} clockid_t; -#endif // ifndef CLOCKID_T - - -#ifndef TIMER_ABSTIME -#define TIMER_ABSTIME 1 -#endif // TIMER_ABSTIME - -struct timespec; - int clock_nanosleep (clockid_t id, int flags, const struct timespec *ts, struct timespec *ots); diff --git a/compat/compat.h b/compat/compat.h index 5aec247..f94015f 100644 --- a/compat/compat.h +++ b/compat/compat.h @@ -28,6 +28,30 @@ #endif +/* clock_* and time-related types */ + +#include + +#if defined(CLOCK_REALTIME) +# define HAVE_CLOCKID_T +#endif + +#ifndef HAVE_CLOCKID_T +typedef enum +{ + CLOCK_REALTIME, + CLOCK_MONOTONIC, + CLOCK_PROCESS_CPUTIME_ID, + CLOCK_THREAD_CPUTIME_ID +} clockid_t; +#endif // !HAVE_CLOCKID_T + +#ifndef TIMER_ABSTIME +#define TIMER_ABSTIME 1 +#endif // !TIMER_ABSTIME + +struct timespec; + #ifdef MISSING_NANOSLEEP #include "clock_nanosleep/clock_nanosleep.h" #endif