Skip to content

Commit

Permalink
Add tests and fix thread priority for VxWorks
Browse files Browse the repository at this point in the history
  • Loading branch information
biabbas committed Oct 22, 2024
1 parent fca7c77 commit eb541fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,27 @@ 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<u8> for ThreadPriorityValue {
type Error = &'static str;
type Error = String;

fn try_from(value: u8) -> Result<Self, Self::Error> {
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
))
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
))]
Expand Down Expand Up @@ -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"
))]
Expand Down

0 comments on commit eb541fb

Please sign in to comment.