diff options
| author | Hasen Judy <hasen.judy@gmail.com> | 2018-05-13 19:33:08 +0900 |
|---|---|---|
| committer | Hasen Judy <hasen.judy@gmail.com> | 2018-05-13 19:33:08 +0900 |
| commit | 9dc2c01aaa52dbf88d1fc33b82b75df8b95105aa (patch) | |
| tree | 66be61dff9a32924c938b07c23451acee6413ebe /src/timings.cpp | |
| parent | 6164672421caf9fafcabc2bbfbeb60c09f932155 (diff) | |
Fix timing on macos
Diffstat (limited to 'src/timings.cpp')
| -rw-r--r-- | src/timings.cpp | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/timings.cpp b/src/timings.cpp index 515cbae55..89280b779 100644 --- a/src/timings.cpp +++ b/src/timings.cpp @@ -29,7 +29,23 @@ u64 win32_time_stamp__freq(void) { return win32_perf_count_freq.QuadPart; } -#elif defined(GB_SYSTEM_OSX) || defined(GB_SYSTEM_UNIX) +#elif defined(GB_SYSTEM_OSX) + +#include <mach/mach_time.h> + +u64 osx_time_stamp_time_now(void) { + return mach_absolute_time(); +} + +u64 osx_time_stamp__freq(void) { + mach_timebase_info_data_t data; + data.numer = 0; + data.denom = 0; + mach_timebase_info(&data); + return (data.numer / data.denom) * 1000000000; +} + +#elif defined(GB_SYSTEM_UNIX) #include <time.h> @@ -52,6 +68,8 @@ u64 unix_time_stamp__freq(void) { return freq; } + + #else #error Implement system #endif @@ -59,7 +77,9 @@ u64 unix_time_stamp__freq(void) { u64 time_stamp_time_now(void) { #if defined(GB_SYSTEM_WINDOWS) return win32_time_stamp_time_now(); -#elif defined(GB_SYSTEM_OSX) || defined(GB_SYSTEM_UNIX) +#elif defined(GB_SYSTEM_OSX) + return osx_time_stamp_time_now(); +#elif defined(GB_SYSTEM_UNIX) return unix_time_stamp_time_now(); #else #error time_stamp_time_now @@ -69,7 +89,9 @@ u64 time_stamp_time_now(void) { u64 time_stamp__freq(void) { #if defined(GB_SYSTEM_WINDOWS) return win32_time_stamp__freq(); -#elif defined(GB_SYSTEM_OSX) || defined(GB_SYSTEM_UNIX) +#elif defined(GB_SYSTEM_OSX) + return osx_time_stamp__freq(); +#elif defined(GB_SYSTEM_UNIX) return unix_time_stamp__freq(); #else #error time_stamp__freq |