From: Alan T. DeKok Date: Mon, 23 Jan 2023 19:31:41 +0000 (-0500) Subject: remove mach functions. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d2361af9cf24a138c4a8d6e58b0aa4a4e8947817;p=thirdparty%2Ffreeradius-server.git remove mach functions. OSX now (and for a long time) has had clock_gettime(). The old code using the mach functions didn't even compile when we tried to not use clock_gettime(). So... nuke the old / broken / unused code. --- diff --git a/src/lib/util/time.c b/src/lib/util/time.c index a9aacf7e358..6f0a8de67be 100644 --- a/src/lib/util/time.c +++ b/src/lib/util/time.c @@ -29,25 +29,6 @@ RCSID("$Id$") #include #include -/* - * Avoid too many ifdef's later in the code. - */ -#if !defined(HAVE_CLOCK_GETTIME) && !defined(__MACH__) -#error clock_gettime is required -#endif - -#if !defined(HAVE_CLOCK_GETTIME) && defined(__MACH__) -/* - * AbsoluteToNanoseconds() has been deprecated, - * but absolutetime_to_nanoseconds() doesn't - * seem to be available, either. - */ -USES_APPLE_DEPRECATED_API -# include -# include -# include -#endif - int64_t const fr_time_multiplier_by_res[] = { [FR_TIME_RES_NSEC] = 1, [FR_TIME_RES_USEC] = NSEC / USEC, @@ -107,12 +88,7 @@ static char const *tz_names[2] = { NULL, NULL }; //!< normal, DST, from localti static long gmtoff[2] = {0, 0}; //!< from localtime_r(), tm_gmtoff static bool isdst = false; //!< from localtime_r(), tm_is_dst -#ifdef HAVE_CLOCK_GETTIME int64_t our_epoch; -#else /* __MACH__ */ -mach_timebase_info_data_t timebase; -uint64_t our_mach_epoch; -#endif /** Get a new our_realtime value * @@ -128,51 +104,25 @@ int fr_time_sync(void) time_t now; /* - * our_realtime represents system time - * at the start of our epoch. + * our_realtime represents system time at the start of our epoch. * - * So to convert a realtime timeval - * to fr_time we just subtract - * our_realtime from the timeval, - * which leaves the number of nanoseconds - * elapsed since our epoch. + * So to convert a realtime timeval to fr_time we just subtract our_realtime from the timeval, + * which leaves the number of nanoseconds elapsed since our epoch. */ -#ifdef HAVE_CLOCK_GETTIME - { - struct timespec ts_realtime, ts_monotime; - - /* - * Call these consecutively to minimise drift... - */ - if (clock_gettime(CLOCK_REALTIME, &ts_realtime) < 0) return -1; - if (clock_gettime(CLOCK_MONOTONIC, &ts_monotime) < 0) return -1; - - atomic_store_explicit(&our_realtime, - fr_time_delta_unwrap(fr_time_delta_from_timespec(&ts_realtime)) - - (fr_time_delta_unwrap(fr_time_delta_from_timespec(&ts_monotime)) - our_epoch), - memory_order_release); + struct timespec ts_realtime, ts_monotime; - now = ts_realtime.tv_sec; - } -#else - { - struct timeval tv_realtime; - uint64_t monotime; + /* + * Call these consecutively to minimise drift... + */ + if (clock_gettime(CLOCK_REALTIME, &ts_realtime) < 0) return -1; + if (clock_gettime(CLOCK_MONOTONIC, &ts_monotime) < 0) return -1; - /* - * Call these consecutively to minimise drift... - */ - (void) gettimeofday(&tv_realtime, NULL); - monotime = mach_absolute_time(); + atomic_store_explicit(&our_realtime, + fr_time_delta_unwrap(fr_time_delta_from_timespec(&ts_realtime)) - + (fr_time_delta_unwrap(fr_time_delta_from_timespec(&ts_monotime)) - our_epoch), + memory_order_release); - atomic_store_explicit(&our_realtime, - fr_time_delta_unwrap(fr_time_delta_from_timeval(&tv_realtime)) - - (monotime - our_mach_epoch) * (timebase.numer / timebase.denom, - memory_order_release)); - - now = tv_realtime.tv_sec; - } -#endif + now = ts_realtime.tv_sec; /* * Get local time zone name, daylight savings, and GMT @@ -199,18 +149,10 @@ int fr_time_sync(void) int fr_time_start(void) { tzset(); /* Populate timezone, daylight and tzname globals */ + struct timespec ts; -#ifdef HAVE_CLOCK_GETTIME - { - struct timespec ts; - - if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) return -1; - our_epoch = fr_time_delta_unwrap(fr_time_delta_from_timespec(&ts)); - } -#else /* __MACH__ is defined */ - mach_timebase_info(&timebase); - our_mach_epoch = mach_absolute_time(); -#endif + if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) return -1; + our_epoch = fr_time_delta_unwrap(fr_time_delta_from_timespec(&ts)); return fr_time_sync(); } diff --git a/src/lib/util/time.h b/src/lib/util/time.h index b52f0fab88f..34383d3ded5 100644 --- a/src/lib/util/time.h +++ b/src/lib/util/time.h @@ -32,6 +32,13 @@ RCSIDH(time_h, "$Id$") #include #include +/* + * Avoid too many ifdef's later in the code. + */ +#if !defined(HAVE_CLOCK_GETTIME) +#error clock_gettime is required +#endif + #ifdef __cplusplus extern "C" { #endif @@ -384,13 +391,7 @@ typedef struct { #define FR_TIME_DUR_MONTH (FR_TIME_DUR_YEAR/12) extern _Atomic int64_t our_realtime; - -#ifdef HAVE_CLOCK_GETTIME extern int64_t our_epoch; -#else /* __MACH__ */ -extern mach_timebase_info_data_t timebase; -extern uint64_t our_mach_epoch; -#endif /** @name fr_unix_time_t scale conversion macros/functions * @@ -960,18 +961,9 @@ static inline int8_t fr_unix_time_cmp(fr_unix_time_t a, fr_unix_time_t b) */ static inline fr_time_t fr_time(void) { -#ifdef HAVE_CLOCK_GETTIME struct timespec ts; (void) clock_gettime(CLOCK_MONOTONIC, &ts); return fr_time_wrap(fr_time_delta_unwrap(fr_time_delta_from_timespec(&ts)) - our_epoch); -#else /* __MACH__ is defined */ - uint64_t when; - - when = mach_absolute_time(); - when -= our_mach_epoch; - - return when * (timebase.numer / timebase.denom); -#endif } int fr_time_start(void);