summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-08-26 00:35:22 +0000
committerGitHub <noreply@github.com>2022-08-26 00:35:22 +0000
commitaa3ee6bc0e246eaa65131dc99ccc6391a99c996c (patch)
tree90fd37295f4199be63bc51923528067ea9fa98cd /src
parent97d6b43bcbbc7de7cb5dd017017aea3ee35e248f (diff)
parent3dc163e780492fa7b2027460d062bc93adc22d77 (diff)
downloadnix-aa3ee6bc0e246eaa65131dc99ccc6391a99c996c.zip
Merge #1804
1804: Add sched_getaffinity and sched_setaffinity on FreeBSD r=asomers a=rtzoeller Co-authored-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
Diffstat (limited to 'src')
-rw-r--r--src/sched.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/sched.rs b/src/sched.rs
index e9a326e2..943ed6ec 100644
--- a/src/sched.rs
+++ b/src/sched.rs
@@ -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;
@@ -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 {
@@ -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
}
}