sys/unix: add sysctlbyname for darwin

This commit is contained in:
Laytan Laats
2024-04-30 00:24:09 +02:00
parent c58da76562
commit cebe6bd982
2 changed files with 23 additions and 25 deletions
+5 -16
View File
@@ -1,21 +1,10 @@
//+private
//+build darwin
package time
import "core:c"
import "core:sys/unix"
foreign import libc "system:System.framework"
foreign libc {
@(link_name="sysctlbyname") _sysctlbyname :: proc(path: cstring, oldp: rawptr, oldlenp: rawptr, newp: rawptr, newlen: int) -> c.int ---
}
_get_tsc_frequency :: proc "contextless" () -> (u64, bool) {
tmp_freq : u64 = 0
tmp_size : i64 = size_of(tmp_freq)
ret := _sysctlbyname("machdep.tsc.frequency", &tmp_freq, &tmp_size, nil, 0)
if ret < 0 {
return 0, false
}
return tmp_freq, true
_get_tsc_frequency :: proc "contextless" () -> (freq: u64, ok: bool) {
unix.sysctlbyname("machdep.tsc.frequency", &freq) or_return
ok = true
return
}