From 4ab5a3bea1a0c7b871bfda90cf3a2568fc859624 Mon Sep 17 00:00:00 2001 From: Doug Kelly Date: Mon, 18 Jan 2021 15:53:50 -0800 Subject: [PATCH] libobs: use clock_gettime_nsec_np() for macOS macOS should use the function clock_gettime_nsec_np() to get the current clock in nanoseconds, instead of manually using mach_absolute_time() and manually adjusting the timebase. This greatly simplifies the platform-specific code to manage the current time in nanoseconds. --- libobs/util/platform-cocoa.m | 37 +----------------------------------- 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/libobs/util/platform-cocoa.m b/libobs/util/platform-cocoa.m index 24ae448f5..e0ec41cd0 100644 --- a/libobs/util/platform-cocoa.m +++ b/libobs/util/platform-cocoa.m @@ -38,44 +38,9 @@ #include "apple/cfstring-utils.h" -/* clock function selection taken from libc++ */ -static uint64_t ns_time_simple() -{ - return mach_absolute_time(); -} - -static double ns_time_compute_factor() -{ - mach_timebase_info_data_t info = {1, 1}; - mach_timebase_info(&info); - return ((double)info.numer) / info.denom; -} - -static uint64_t ns_time_full() -{ - static double factor = 0.; - if (factor == 0.) - factor = ns_time_compute_factor(); - return (uint64_t)(mach_absolute_time() * factor); -} - -typedef uint64_t (*time_func)(); - -static time_func ns_time_select_func() -{ - mach_timebase_info_data_t info = {1, 1}; - mach_timebase_info(&info); - if (info.denom == info.numer) - return ns_time_simple; - return ns_time_full; -} - uint64_t os_gettime_ns(void) { - static time_func f = NULL; - if (!f) - f = ns_time_select_func(); - return f(); + return clock_gettime_nsec_np(CLOCK_UPTIME_RAW); } /* gets the location [domain mask]/Library/Application Support/[name] */