diff --git a/src/lib.rs b/src/lib.rs index dd74009..a62cdd7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -246,19 +246,23 @@ impl std::error::Error for Error {} pub struct ThreadPriorityValue(u8); impl ThreadPriorityValue { /// The maximum value for a thread priority. - pub const MAX: u8 = 99; + pub const MAX: u8 = if cfg!(target_os = "vxworks") { 255 } else { 99 }; /// The minimum value for a thread priority. pub const MIN: u8 = 0; } impl std::convert::TryFrom for ThreadPriorityValue { - type Error = &'static str; + type Error = String; fn try_from(value: u8) -> Result { if (Self::MIN..=Self::MAX).contains(&value) { Ok(Self(value)) } else { - Err("The value is not in the range of [0;99]") + Err(format!( + "The value is not in the range of [{}; {}]", + Self::MIN, + Self::MAX + )) } } } @@ -810,7 +814,7 @@ pub trait ThreadScopeExt<'scope> { } #[rustversion::since(1.63)] -impl<'scope, 'env> ThreadScopeExt<'scope> for std::thread::Scope<'scope, 'env> { +impl<'scope> ThreadScopeExt<'scope> for std::thread::Scope<'scope, '_> { fn spawn_with_priority( &'scope self, priority: ThreadPriority, diff --git a/src/unix.rs b/src/unix.rs index 32b7466..cec19dc 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -10,10 +10,10 @@ use std::convert::TryFrom; use libc::SCHED_NORMAL as SCHED_OTHER; #[cfg(not(target_os = "android"))] use libc::SCHED_OTHER; -#[cfg(any(target_os = "linux", target_os = "android"))] -use libc::{SCHED_BATCH, SCHED_IDLE}; #[cfg(target_os = "vxworks")] use libc::SCHED_SPORADIC; +#[cfg(any(target_os = "linux", target_os = "android"))] +use libc::{SCHED_BATCH, SCHED_IDLE}; use libc::{SCHED_FIFO, SCHED_RR}; use crate::{Error, ThreadPriority, ThreadPriorityValue}; @@ -590,7 +590,11 @@ pub fn set_thread_priority_and_policy( // On VxWorks, macOS and iOS it is possible to set the priority // this way. if matches!(policy, ThreadSchedulePolicy::Realtime(_)) - || cfg!(any(target_os = "macos", target_os = "ios", target_os = "vxworks")) + || cfg!(any( + target_os = "macos", + target_os = "ios", + target_os = "vxworks" + )) { // If the policy is a realtime one, the priority is set via // pthread_setschedparam. @@ -614,7 +618,11 @@ pub fn set_thread_priority_and_policy( } else { //VxWorks does not have set priority function #[cfg(target_os = "vxworks")] - unsafe fn setpriority( _which: u32, _who: u32, _priority: libc::c_int) -> libc::c_int { + unsafe fn setpriority( + _which: u32, + _who: u32, + _priority: libc::c_int, + ) -> libc::c_int { panic!("Set priority function not supported by vxworks"); } diff --git a/tests/unix.rs b/tests/unix.rs index ff144c2..e699ef7 100644 --- a/tests/unix.rs +++ b/tests/unix.rs @@ -46,6 +46,7 @@ fn get_and_set_priority_with_normal_policies( #[cfg(any( target_os = "macos", target_os = "openbsd", + target_os = "vxworks", target_os = "freebsd", target_os = "netbsd" ))] @@ -107,6 +108,7 @@ fn set_priority_with_normal_policy_but_with_invalid_value(#[case] policy: Thread #[cfg(any( target_os = "macos", target_os = "openbsd", + target_os = "vxworks", target_os = "freebsd", target_os = "netbsd" ))]