Unwrap cpu affinity syscalls.

This commit is contained in:
Jeroen van Rijn
2026-02-09 19:01:43 +01:00
parent fa44c64c42
commit 454ad1f4b8
2 changed files with 5 additions and 5 deletions

View File

@@ -60,7 +60,7 @@ _get_current_thread_id :: proc "contextless" () -> int {
_get_processor_core_count :: proc() -> (core_count: int) {
cpu_set: [128]u64
if err := linux.sched_getaffinity(0, size_of(cpu_set), &cpu_set); err != nil {
if _, err := linux.sched_getaffinity(0, size_of(cpu_set), &cpu_set); err == nil {
for set in cpu_set {
core_count += int(intrinsics.count_ones(set))
}

View File

@@ -2616,9 +2616,9 @@ futex :: proc{
If you are running on a system with less than 128 cores you can use `linux.Cpu_Set` as the type for the mask argument.
Otherwise use an array of integers.
*/
sched_setaffinity :: proc "contextless" (pid: Pid, cpusetsize: uint, mask: rawptr) -> (Errno) {
sched_setaffinity :: proc "contextless" (pid: Pid, cpusetsize: uint, mask: rawptr) -> (int, Errno) {
ret := syscall(SYS_sched_setaffinity, pid, cpusetsize, mask)
return Errno(-ret)
return errno_unwrap(ret, int)
}
/*
@@ -2628,9 +2628,9 @@ sched_setaffinity :: proc "contextless" (pid: Pid, cpusetsize: uint, mask: rawpt
If you are running on a system with less than 128 cores you can use `linux.Cpu_Set` as the type for the mask argument.
Otherwise use an array of integers.
*/
sched_getaffinity :: proc "contextless" (pid: Pid, cpusetsize: uint, mask: rawptr) -> (Errno) {
sched_getaffinity :: proc "contextless" (pid: Pid, cpusetsize: uint, mask: rawptr) -> (int, Errno) {
ret := syscall(SYS_sched_getaffinity, pid, cpusetsize, mask)
return Errno(-ret)
return errno_unwrap(ret, int)
}
// TODO(flysand): set_thread_area