diff --git a/common/Timer.cpp b/common/Timer.cpp index 2d4a2419119ab..7a54e0c0fd5c6 100644 --- a/common/Timer.cpp +++ b/common/Timer.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #else #include #include @@ -86,6 +87,53 @@ namespace Common return static_cast(ns * s_counter_frequency); } +#elif defined(__APPLE__) + static double getCounterToNS() + { + mach_timebase_info_data_t info; + if (mach_timebase_info(&info) != KERN_SUCCESS) + abort(); + return static_cast(info.numer) / static_cast(info.denom); + } + + static double s_counter_to_ns = getCounterToNS(); + static double s_counter_to_ms = s_counter_to_ns / 1000000; + static double s_counter_to_s = s_counter_to_ms / 1000; + + Timer::Value Timer::GetCurrentValue() + { + return mach_absolute_time(); + } + + double Timer::ConvertValueToNanoseconds(Value value) + { + return static_cast(value) * s_counter_to_ns; + } + + double Timer::ConvertValueToMilliseconds(Value value) + { + return static_cast(value) * s_counter_to_ms; + } + + double Timer::ConvertValueToSeconds(Value value) + { + return static_cast(value) * s_counter_to_s; + } + + Timer::Value Timer::ConvertSecondsToValue(double s) + { + return static_cast(s / s_counter_to_s); + } + + Timer::Value Timer::ConvertMillisecondsToValue(double ms) + { + return static_cast(ms / s_counter_to_ms); + } + + Timer::Value Timer::ConvertNanosecondsToValue(double ns) + { + return static_cast(ns / s_counter_to_ns); + } #else Timer::Value Timer::GetCurrentValue()