aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil/util.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-01-10 08:24:00 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-01-10 08:24:00 +0000
commit187dc259dd3cc1bdfaf0d94cccf2deba9943f307 (patch)
treebb833719812cf9dc808ca6efad6336ad3f5afcee /src/libutil/util.c
parent9a821ac77f2e0c8807ac5bf84d431070df618166 (diff)
downloadrspamd-187dc259dd3cc1bdfaf0d94cccf2deba9943f307.tar.gz
rspamd-187dc259dd3cc1bdfaf0d94cccf2deba9943f307.zip
[Minor] Improve clock accuracy on osx
Diffstat (limited to 'src/libutil/util.c')
-rw-r--r--src/libutil/util.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/libutil/util.c b/src/libutil/util.c
index bf4678bbe..035369e67 100644
--- a/src/libutil/util.c
+++ b/src/libutil/util.c
@@ -51,6 +51,9 @@
#endif
#ifdef __APPLE__
#include <mach/mach_time.h>
+#include <mach/mach_init.h>
+#include <mach/thread_act.h>
+#include <mach/mach_port.h>
#endif
#ifdef WITH_GPERF_TOOLS
#include <gperftools/profiler.h>
@@ -1836,6 +1839,18 @@ rspamd_get_virtual_ticks (void)
# endif
res = (double)ts.tv_sec + ts.tv_nsec / 1000000000.;
+#elif defined(__APPLE__)
+ thread_port_t thread = mach_thread_self ();
+
+ mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT;
+ thread_basic_info_data_t info;
+ if (thread_info (thread, THREAD_BASIC_INFO, (thread_info_t)&info, &count) != KERN_SUCCESS) {
+ return -1;
+ }
+
+ res = info.user_time.seconds + info.system_time.seconds;
+ res += ((gdouble)(info.user_time.microseconds + info.system_time.microseconds)) / 1e6;
+ mach_port_deallocate(mach_task_self(), thread);
#else
res = clock () / (double)CLOCKS_PER_SEC;
#endif