diff options
| author | Colin Davidson <colrdavidson@gmail.com> | 2023-02-19 20:23:35 -0800 |
|---|---|---|
| committer | Colin Davidson <colrdavidson@gmail.com> | 2023-02-19 20:23:35 -0800 |
| commit | 6a2ef1f4f3dccaccafd6d28eb9096741e95fb734 (patch) | |
| tree | 7b155716171a25a1eaa453355507e1c1f503204c | |
| parent | 051c9cb564b2108a88f24500460602901efb452b (diff) | |
add osx support
| -rw-r--r-- | core/sys/darwin/xnu_system_call_wrappers.odin | 2 | ||||
| -rw-r--r-- | core/time/tsc_darwin.odin | 23 |
2 files changed, 24 insertions, 1 deletions
diff --git a/core/sys/darwin/xnu_system_call_wrappers.odin b/core/sys/darwin/xnu_system_call_wrappers.odin index 685f75ffa..c1d2fd6f7 100644 --- a/core/sys/darwin/xnu_system_call_wrappers.odin +++ b/core/sys/darwin/xnu_system_call_wrappers.odin @@ -416,4 +416,4 @@ syscall_chdir :: #force_inline proc(path: cstring) -> c.int { syscall_fchdir :: #force_inline proc(fd: c.int, path: cstring) -> c.int { return cast(c.int)intrinsics.syscall(unix_offset_syscall(.getentropy), uintptr(fd), transmute(uintptr)path) -}
\ No newline at end of file +} diff --git a/core/time/tsc_darwin.odin b/core/time/tsc_darwin.odin new file mode 100644 index 000000000..f2796470e --- /dev/null +++ b/core/time/tsc_darwin.odin @@ -0,0 +1,23 @@ +//+private +//+build darwin +package time + +import "core:sys/darwin" + +_get_tsc_frequency :: proc "contextless" () -> u64 { + @(static) frequency : u64 = 0 + if frequency > 0 { + return frequency + } + + tmp_freq : u64 = 0 + tmp_size : i64 = size_of(tmp_freq) + ret := darwin.syscall_sysctlbyname("machdep.tsc.frequency", &tmp_freq, &tmp_size, nil, 0) + if ret < 0 { + frequency = 1 + return 0 + } + + frequency = tmp_freq + return frequency +} |