]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
platform: Add a timer implementation for OS X
authorJan Tulak <jtulak@redhat.com>
Tue, 13 Oct 2015 23:58:23 +0000 (10:58 +1100)
committerDave Chinner <david@fromorbit.com>
Tue, 13 Oct 2015 23:58:23 +0000 (10:58 +1100)
OS X does not have the timer used in xfs_repair.
Add a simple implementation providing the required
capabilities.

Signed-off-by: Jan Tulak <jtulak@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
include/darwin.h
repair/progress.c

index 1409c9198a4f61d2ae513fba36e99bd9124b2d1e..0d2f17582ba431661b77d14ac9265f5093f07a67 100644 (file)
@@ -28,6 +28,7 @@
 #include <sys/ioctl.h>
 #include <sys/mount.h>
 #include <sys/types.h>
+#include <sys/time.h>
 #include <ftw.h>
 #include <mach/mach_time.h>
 #include <inttypes.h>
@@ -168,4 +169,51 @@ platform_discard_blocks(int fd, uint64_t start, uint64_t len)
        return 0;
 }
 
+/*
+ * POSIX timer replacement.
+ * It really just do the minimum we need for xfs_repair.
+ * Also, as setitimer can't create multiple timers,
+ * the timerid things are useless - we have only one ITIMER_REAL
+ * timer.
+ */
+#define CLOCK_REALTIME ITIMER_REAL
+#define itimerspec itimerval
+typedef uint64_t timer_t;
+typedef double   timer_c;
+typedef clock_id_t clockid_t;
+
+
+static inline int timer_create (clockid_t __clock_id,
+                         struct sigevent *__restrict __evp,
+                         timer_t *__restrict timer)
+{
+       // set something, to initialize the variable, just in case
+       *timer = 0;
+       return 0;
+}
+
+static inline int timer_settime (timer_t timerid, int flags,
+                          const struct itimerspec *__restrict timerspec,
+                          struct itimerspec *__restrict ovalue)
+{
+       return setitimer(ITIMER_REAL, timerspec, ovalue);
+}
+
+static inline int timer_delete (timer_t timerid)
+{
+       struct itimerspec timespec;
+
+       timespec.it_interval.tv_sec=0;
+       timespec.it_interval.tv_usec=0;
+       timespec.it_value.tv_sec=0;
+       timespec.it_value.tv_usec=0;
+
+       return setitimer(ITIMER_REAL, &timespec, NULL);
+}
+
+static inline int timer_gettime (timer_t timerid, struct itimerspec *value)
+{
+       return getitimer(ITIMER_REAL, value);
+}
+
 #endif /* __XFS_DARWIN_H__ */
index 27cbaefbfad4cfee5859544482543bf7135c2f6a..418b8034ab9bacae843569ee1f4d702e181fa197 100644 (file)
@@ -183,10 +183,9 @@ progress_rpt_thread (void *p)
         * Specify a repeating timer that fires each MSG_INTERVAL seconds.
         */
 
+       memset(&timespec, 0, sizeof(timespec));
        timespec.it_value.tv_sec = msgp->interval;
-       timespec.it_value.tv_nsec = 0;
        timespec.it_interval.tv_sec = msgp->interval;
-       timespec.it_interval.tv_nsec = 0;
 
        if (timer_create (CLOCK_REALTIME, NULL, &timerid))
                do_error(_("progress_rpt: cannot create timer\n"));