Skip to content

Commit aa3ee6b

Browse files
bors[bot]rtzoeller
andauthored
Merge #1804
1804: Add sched_getaffinity and sched_setaffinity on FreeBSD r=asomers a=rtzoeller Co-authored-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
2 parents 97d6b43 + 3dc163e commit aa3ee6b

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ This project adheres to [Semantic Versioning](https://semver.org/).
66
## [Unreleased] - ReleaseDate
77
### Added
88

9+
- Added `sched_getaffinity` and `sched_setaffinity` on FreeBSD.
10+
([#1804](https://github.com/nix-rust/nix/pull/1804))
911
- Added `line_discipline` field to `Termios` on Linux, Android and Haiku
10-
([#1805](https://github.com/nix-rust/nix/pull/1805))
12+
([#1805](https://github.com/nix-rust/nix/pull/1805))
1113

1214
### Changed
1315

src/sched.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ mod sched_linux_like {
142142
}
143143
}
144144

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

148-
#[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "linux"))]
148+
#[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "freebsd", target_os = "linux"))]
149149
mod sched_affinity {
150150
use crate::errno::Errno;
151151
use std::mem;
@@ -157,10 +157,13 @@ mod sched_affinity {
157157
/// sched_getaffinity for example.
158158
///
159159
/// This is a wrapper around `libc::cpu_set_t`.
160-
#[repr(C)]
160+
#[repr(transparent)]
161161
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
162162
pub struct CpuSet {
163+
#[cfg(not(target_os = "freebsd"))]
163164
cpu_set: libc::cpu_set_t,
165+
#[cfg(target_os = "freebsd")]
166+
cpu_set: libc::cpuset_t,
164167
}
165168

166169
impl CpuSet {
@@ -205,7 +208,12 @@ mod sched_affinity {
205208

206209
/// Return the maximum number of CPU in CpuSet
207210
pub const fn count() -> usize {
208-
8 * mem::size_of::<libc::cpu_set_t>()
211+
#[cfg(not(target_os = "freebsd"))]
212+
let bytes = mem::size_of::<libc::cpu_set_t>();
213+
#[cfg(target_os = "freebsd")]
214+
let bytes = mem::size_of::<libc::cpuset_t>();
215+
216+
8 * bytes
209217
}
210218
}
211219

test/test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ mod test_resource;
3636
#[cfg(any(
3737
target_os = "android",
3838
target_os = "dragonfly",
39+
all(target_os = "freebsd", fbsd14),
3940
target_os = "linux"
4041
))]
4142
mod test_sched;

0 commit comments

Comments
 (0)