Simplification for netbsd-specific code (#750)
the cpuset api is already present in libc...
This commit is contained in:
parent
7257631ed5
commit
556bdc828c
@ -716,18 +716,14 @@ mod netbsd {
|
|||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
use std::thread::available_parallelism;
|
use std::thread::available_parallelism;
|
||||||
|
|
||||||
use libc::{_cpuset, pthread_self, pthread_setaffinity_np};
|
use libc::{
|
||||||
|
_cpuset, _cpuset_create, _cpuset_destroy, _cpuset_set, _cpuset_size, pthread_self,
|
||||||
|
pthread_setaffinity_np,
|
||||||
|
};
|
||||||
|
|
||||||
use super::CoreId;
|
use super::CoreId;
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
fn _cpuset_create() -> *mut _cpuset;
|
|
||||||
fn _cpuset_destroy(c: *mut _cpuset);
|
|
||||||
fn _cpuset_set(i: usize, c: *mut _cpuset) -> i32;
|
|
||||||
fn _cpuset_size(c: *const _cpuset) -> usize;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(trivial_numeric_casts)]
|
#[allow(trivial_numeric_casts)]
|
||||||
pub fn get_core_ids() -> Result<Vec<CoreId>, Error> {
|
pub fn get_core_ids() -> Result<Vec<CoreId>, Error> {
|
||||||
Ok((0..(usize::from(available_parallelism()?)))
|
Ok((0..(usize::from(available_parallelism()?)))
|
||||||
@ -739,7 +735,7 @@ mod netbsd {
|
|||||||
pub fn set_for_current(core_id: CoreId) -> Result<(), Error> {
|
pub fn set_for_current(core_id: CoreId) -> Result<(), Error> {
|
||||||
let set = new_cpuset();
|
let set = new_cpuset();
|
||||||
|
|
||||||
unsafe { _cpuset_set(core_id.id, set) };
|
unsafe { _cpuset_set(core_id.id as u64, set) };
|
||||||
// Set the current thread's core affinity.
|
// Set the current thread's core affinity.
|
||||||
let result = unsafe {
|
let result = unsafe {
|
||||||
pthread_setaffinity_np(
|
pthread_setaffinity_np(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user