Skip to content

Commit

Permalink
Merge #1804
Browse files Browse the repository at this point in the history
1804: Add sched_getaffinity and sched_setaffinity on FreeBSD r=asomers a=rtzoeller



Co-authored-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
  • Loading branch information
bors[bot] and rtzoeller committed Aug 26, 2022
2 parents 97d6b43 + 3dc163e commit aa3ee6b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
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

0 comments on commit aa3ee6b

Please sign in to comment.