]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
remove mach functions.
authorAlan T. DeKok <aland@freeradius.org>
Mon, 23 Jan 2023 19:31:41 +0000 (14:31 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 23 Jan 2023 21:34:48 +0000 (16:34 -0500)
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.

src/lib/util/time.c
src/lib/util/time.h

index a9aacf7e3588c65e3f7befd481d363d9d367f84a..6f0a8de67bea302af14d838d385ff937c329589f 100644 (file)
@@ -29,25 +29,6 @@ RCSID("$Id$")
 #include <freeradius-devel/util/time.h>
 #include <freeradius-devel/util/misc.h>
 
-/*
- *     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 <CoreServices/CoreServices.h>
-#  include <mach/mach.h>
-#  include <mach/mach_time.h>
-#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();
 }
index b52f0fab88f2854f4752c3cb1442db2d45386b12..34383d3ded55ba3067409ba0fc6cb5ddc0e31224 100644 (file)
@@ -32,6 +32,13 @@ RCSIDH(time_h, "$Id$")
 #include <stdio.h>
 #include <sys/time.h>
 
+/*
+ *     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);