mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-22 22:35:19 +00:00
Fix incorrect timings on macOS
This commit is contained in:
@@ -33,22 +33,23 @@ gb_internal u64 win32_time_stamp__freq(void) {
|
||||
|
||||
#include <mach/mach_time.h>
|
||||
|
||||
gb_internal u64 osx_time_stamp_time_now(void) {
|
||||
return mach_absolute_time();
|
||||
}
|
||||
|
||||
gb_internal u64 osx_time_stamp__freq(void) {
|
||||
gb_internal mach_timebase_info_data_t osx_init_timebase_info(void) {
|
||||
mach_timebase_info_data_t data;
|
||||
data.numer = 0;
|
||||
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
|
||||
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_local_persist mach_timebase_info_data_t data = osx_init_timebase_info();
|
||||
return (mach_absolute_time() * cast(u64)data.numer) / cast(u64)data.denom; // Effectively converts to nanoseconds
|
||||
}
|
||||
|
||||
gb_internal u64 osx_time_stamp__freq(void) {
|
||||
return 1000000000ull; // Nanoseconds to seconds
|
||||
}
|
||||
|
||||
#elif defined(GB_SYSTEM_UNIX)
|
||||
|
||||
Reference in New Issue
Block a user