diff options
| author | Laytan Laats <laytanlaats@hotmail.com> | 2024-07-27 04:20:03 +0200 |
|---|---|---|
| committer | Laytan Laats <laytanlaats@hotmail.com> | 2024-08-14 01:44:35 +0200 |
| commit | efe68c2e24e0a38e591f146822ed93904e4193d7 (patch) | |
| tree | c2ac0ed3d08746495aa6adcd7a1c1ab052a7ee76 /core/prof | |
| parent | ac68a9d52c3a9edc587e1ccab747613baf6f89de (diff) | |
posix: add package
Diffstat (limited to 'core/prof')
| -rw-r--r-- | core/prof/spall/spall_unix.odin | 33 |
1 files changed, 12 insertions, 21 deletions
diff --git a/core/prof/spall/spall_unix.odin b/core/prof/spall/spall_unix.odin index 174b3a11b..fc05b8525 100644 --- a/core/prof/spall/spall_unix.odin +++ b/core/prof/spall/spall_unix.odin @@ -5,22 +5,7 @@ package spall // Only for types. import "core:os" -when ODIN_OS == .Darwin { - foreign import libc "system:System.framework" -} else { - foreign import libc "system:c" -} - -timespec :: struct { - tv_sec: i64, // seconds - tv_nsec: i64, // nanoseconds -} - -foreign libc { - __error :: proc() -> ^i32 --- - @(link_name="write") _unix_write :: proc(handle: os.Handle, buffer: rawptr, count: uint) -> int --- - @(link_name="clock_gettime") _unix_clock_gettime :: proc(clock_id: u64, timespec: ^timespec) -> i32 --- -} +import "core:sys/posix" MAX_RW :: 0x7fffffff @@ -32,7 +17,7 @@ _write :: proc "contextless" (fd: os.Handle, data: []byte) -> (n: int, err: os.E for n < len(data) { chunk := data[:min(len(data), MAX_RW)] - written := _unix_write(fd, raw_data(chunk), len(chunk)) + written := posix.write(posix.FD(fd), raw_data(chunk), len(chunk)) if written < 0 { return n, os.get_last_error() } @@ -42,11 +27,17 @@ _write :: proc "contextless" (fd: os.Handle, data: []byte) -> (n: int, err: os.E return n, nil } -CLOCK_MONOTONIC_RAW :: 4 // NOTE(tetra): "RAW" means: Not adjusted by NTP. +// NOTE(tetra): "RAW" means: Not adjusted by NTP. +when ODIN_OS == .Darwin { + CLOCK :: posix.Clock(4) // CLOCK_MONOTONIC_RAW +} else { + // It looks like the BSDs don't have a CLOCK_MONOTONIC_RAW equivalent. + CLOCK :: posix.Clock.MONOTONIC +} @(no_instrumentation) _tick_now :: proc "contextless" () -> (ns: i64) { - t: timespec - _unix_clock_gettime(CLOCK_MONOTONIC_RAW, &t) - return t.tv_sec*1e9 + t.tv_nsec + t: posix.timespec + posix.clock_gettime(CLOCK, &t) + return i64(t.tv_sec)*1e9 + i64(t.tv_nsec) } |