Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2013-01-06 05:42:58 +0400
committerFelix Fietkau <nbd@openwrt.org>2013-01-06 05:42:58 +0400
commitaa4f3bde06ea1410f1835590ae025e044f2364fb (patch)
tree03563502534eee8adcaf8a6c0ac88d3244c9d095 /utils.c
parent76f584c7612dc5ac8090da19b50ab159cb5c586a (diff)
uloop: add a clock_gettime() implementation for mac os x
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/utils.c b/utils.c
index 4589da8..078a8a1 100644
--- a/utils.c
+++ b/utils.c
@@ -52,3 +52,43 @@ void *__calloc_a(size_t len, ...)
return ret;
}
+
+#ifdef __APPLE__
+#include <mach/mach_time.h>
+
+static void clock_gettime_realtime(struct timespec *tv)
+{
+ struct timeval _tv;
+
+ gettimeofday(&_tv, NULL);
+ tv->tv_sec = _tv.tv_sec;
+ tv->tv_nsec = _tv.tv_usec * 1000;
+}
+
+static void clock_gettime_monotonic(struct timespec *tv)
+{
+ mach_timebase_info_data_t info;
+ float sec;
+ uint64_t val;
+
+ mach_timebase_info(&info);
+
+ val = mach_absolute_time();
+ tv->tv_nsec = (val * info.numer / info.denom) % 1000000000;
+
+ sec = val;
+ sec *= info.numer;
+ sec /= info.denom;
+ sec /= 1000000000;
+ tv->tv_sec = sec;
+}
+
+void clock_gettime(int type, struct timespec *tv)
+{
+ if (type == CLOCK_REALTIME)
+ return clock_gettime_realtime(tv);
+ else
+ return clock_gettime_monotonic(tv);
+}
+
+#endif