Skip to content

Commit

Permalink
Add sched_getaffinity and sched_setaffinity on FreeBSD
Browse files Browse the repository at this point in the history
  • Loading branch information
rtzoeller committed Aug 20, 2022
1 parent 2a8b438 commit 08dc685
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ This project adheres to [Semantic Versioning](https://semver.org/).
## [Unreleased] - ReleaseDate
### Added

- Added `sched_getaffinity` and `sched_setaffinity` on FreeBSD.
([#1804](https://github.com/nix-rust/nix/pull/1804))

### Changed

- The MSRV is now 1.56.1
Expand Down
16 changes: 12 additions & 4 deletions src/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ mod sched_linux_like {
}
}

#[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "linux"))]
#[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "freebsd", target_os = "linux"))]
pub use self::sched_affinity::*;

#[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "linux"))]
#[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "freebsd", target_os = "linux"))]
mod sched_affinity {
use crate::errno::Errno;
use std::mem;
Expand All @@ -157,10 +157,13 @@ mod sched_affinity {
/// sched_getaffinity for example.
///
/// This is a wrapper around `libc::cpu_set_t`.
#[repr(C)]
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct CpuSet {
#[cfg(not(target_os = "freebsd"))]
cpu_set: libc::cpu_set_t,
#[cfg(target_os = "freebsd")]
cpu_set: libc::cpuset_t,
}

impl CpuSet {
Expand Down Expand Up @@ -205,7 +208,12 @@ mod sched_affinity {

/// Return the maximum number of CPU in CpuSet
pub const fn count() -> usize {
8 * mem::size_of::<libc::cpu_set_t>()
#[cfg(not(target_os = "freebsd"))]
let bytes = mem::size_of::<libc::cpu_set_t>();
#[cfg(target_os = "freebsd")]
let bytes = mem::size_of::<libc::cpuset_t>();

8 * bytes
}
}

Expand Down
1 change: 1 addition & 0 deletions test/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ mod test_resource;
#[cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "linux"
))]
mod test_sched;
Expand Down

0 comments on commit 08dc685

Please sign in to comment.