Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sched_getaffinity and sched_setaffinity on FreeBSD #1804

Merged
merged 1 commit into from Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Expand Up @@ -6,8 +6,10 @@ 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))
- Added `line_discipline` field to `Termios` on Linux, Android and Haiku
([#1805](https://github.com/nix-rust/nix/pull/1805))
([#1805](https://github.com/nix-rust/nix/pull/1805))

### Changed

Expand Down
16 changes: 12 additions & 4 deletions src/sched.rs
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
Expand Up @@ -36,6 +36,7 @@ mod test_resource;
#[cfg(any(
target_os = "android",
target_os = "dragonfly",
all(target_os = "freebsd", fbsd14),
target_os = "linux"
))]
mod test_sched;
Expand Down