mirror of
https://github.com/odin-lang/Odin.git
synced 2026-02-11 22:08:42 +00:00
Implement get_processor_core_count without libc for Linux.
This commit is contained in:
@@ -57,8 +57,15 @@ _get_current_thread_id :: proc "contextless" () -> int {
|
||||
}
|
||||
|
||||
@(private="package")
|
||||
_get_processor_core_count :: proc() -> int {
|
||||
return int(_unix_get_nprocs())
|
||||
_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 != linux.Errno(-1) {
|
||||
for set in cpu_set {
|
||||
core_count += int(intrinsics.count_ones(set))
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@(private="package")
|
||||
|
||||
Reference in New Issue
Block a user