Module: kamailio
Branch: master
Commit: a46f13516ae7eb3f5a5598f3529bad58da4970b7
URL:
https://github.com/kamailio/kamailio/commit/a46f13516ae7eb3f5a5598f3529bad5…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2016-05-05T08:38:12+02:00
core: added alternative for clock_gettime() on mac os x
---
Modified: ser_time.h
Modified: timer.c
---
Diff:
https://github.com/kamailio/kamailio/commit/a46f13516ae7eb3f5a5598f3529bad5…
Patch:
https://github.com/kamailio/kamailio/commit/a46f13516ae7eb3f5a5598f3529bad5…
---
diff --git a/ser_time.h b/ser_time.h
index 538e5af..b1ecfdf 100644
--- a/ser_time.h
+++ b/ser_time.h
@@ -37,4 +37,7 @@ time_t ser_time(time_t* t);
* WARNING: ignores tz (it's obsolete anyway) */
int ser_gettimeofday(struct timeval* tv, const struct timezone *tz);
+/* portable implementation for clock_gettime(CLOCK_REALTIME, ts) */
+int ser_clock_gettime(struct timespec *ts);
+
#endif /* _ser_time_h */
diff --git a/timer.c b/timer.c
index 111c63f..c6ccea8 100644
--- a/timer.c
+++ b/timer.c
@@ -37,6 +37,12 @@
#include <stdlib.h> /* random, debugging only */
#include "error.h"
#include "signals.h"
+
+#ifdef __OS_darwin
+#include <mach/clock.h>
+#include <mach/mach.h>
+#endif
+
/*
#include "config.h"
*/
@@ -1153,4 +1159,22 @@ void slow_timer_main()
}
+int ser_clock_gettime(struct timespec *ts)
+{
+#ifdef __OS_darwin
+ clock_serv_t cclock;
+ mach_timespec_t mts;
+
+ /* OS X does not have clock_gettime, use clock_get_time */
+ host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
+ clock_get_time(cclock, &mts);
+ mach_port_deallocate(mach_task_self(), cclock);
+ ts->tv_sec = mts.tv_sec;
+ ts->tv_nsec = mts.tv_nsec;
+ return 0;
+#else
+ return clock_gettime(CLOCK_REALTIME, ts);
+#endif
+}
+
#endif