mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 08:08:50 +00:00
Merge pull request #3347 from harold-b/macos-timing-fix
Fix incorrect timings on macOS
This commit is contained in:
+12
-11
@@ -33,22 +33,23 @@ gb_internal u64 win32_time_stamp__freq(void) {
|
|||||||
|
|
||||||
#include <mach/mach_time.h>
|
#include <mach/mach_time.h>
|
||||||
|
|
||||||
|
gb_internal mach_timebase_info_data_t osx_init_timebase_info(void) {
|
||||||
|
mach_timebase_info_data_t data;
|
||||||
|
data.numer = 0;
|
||||||
|
data.denom = 0;
|
||||||
|
kern_return_t r = mach_timebase_info(&data);
|
||||||
|
GB_ASSERT(r == KERN_SUCCESS);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
gb_internal u64 osx_time_stamp_time_now(void) {
|
gb_internal u64 osx_time_stamp_time_now(void) {
|
||||||
return mach_absolute_time();
|
return mach_absolute_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
gb_internal u64 osx_time_stamp__freq(void) {
|
gb_internal u64 osx_time_stamp__freq(void) {
|
||||||
mach_timebase_info_data_t data;
|
gb_local_persist mach_timebase_info_data_t data = osx_init_timebase_info();
|
||||||
data.numer = 0;
|
return 1000000000ull * cast(u64)data.denom / cast(u64)data.numer;
|
||||||
data.denom = 0;
|
|
||||||
mach_timebase_info(&data);
|
|
||||||
#if defined(GB_CPU_ARM)
|
|
||||||
// NOTE(bill, 2021-02-25): M1 Chip seems to have a different freq count
|
|
||||||
// TODO(bill): Is this truly correct?
|
|
||||||
return (1000000llu * cast(u64)data.numer) / cast(u64)data.denom;
|
|
||||||
#else
|
|
||||||
return (1000000000llu * cast(u64)data.numer) / cast(u64)data.denom;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(GB_SYSTEM_UNIX)
|
#elif defined(GB_SYSTEM_UNIX)
|
||||||
|
|||||||
Reference in New Issue
Block a user