Skip to content

Commit

Permalink
Add VxWorks code
Browse files Browse the repository at this point in the history
  • Loading branch information
biabbas committed Oct 18, 2024
1 parent 77360b7 commit bbd65de
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ fn errno() -> libc::c_int {
*libc::__errno_location()
} else if #[cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd"))] {
*libc::__error()
} else if #[cfg(target_os = "vxworks")] {
libc::errnoGet()
} else {
compile_error!("Your OS is probably not supported.")
}
Expand All @@ -67,6 +69,8 @@ fn set_errno(number: libc::c_int) {
*libc::__errno_location() = number;
} else if #[cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd"))] {
*libc::__error() = number;
} else if #[cfg(target_os = "vxworks")] {
let _ = libc::errnoSet(number);
} else {
compile_error!("Your OS is probably not supported.")
}
Expand Down Expand Up @@ -171,6 +175,9 @@ pub enum RealtimeThreadSchedulePolicy {
Fifo,
/// A round-robin policy
RoundRobin,
// Policy similar to Fifo
#[cfg(target_os = "vxworks")]
Sporadic,
/// A deadline policy. Note, due to Linux expecting a pid_t and not a pthread_t, the given
/// [ThreadId](struct.ThreadId) will be interpreted as a pid_t. This policy is NOT
/// POSIX-compatible, so we only include it for linux targets.
Expand All @@ -186,6 +193,8 @@ impl RealtimeThreadSchedulePolicy {
match self {
RealtimeThreadSchedulePolicy::Fifo => SCHED_FIFO,
RealtimeThreadSchedulePolicy::RoundRobin => SCHED_RR,
#[cfg(target_os = "vxworks")]
RealtimeThreadSchedulePolicy::Sporadic => SCHED_SPORADIC,
#[cfg(all(
any(target_os = "linux", target_os = "android"),
not(target_arch = "wasm32")
Expand Down Expand Up @@ -284,6 +293,10 @@ impl ThreadSchedulePolicy {
SCHED_RR => Ok(ThreadSchedulePolicy::Realtime(
RealtimeThreadSchedulePolicy::RoundRobin,
)),
#[cfg(target_os = "vxworks")]
SCHED_SPORADIC => Ok(ThreadSchedulePolicy::Realtime(
RealtimeThreadSchedulePolicy::Sporadic,
)),
#[cfg(all(
any(target_os = "linux", target_os = "android"),
not(target_arch = "wasm32")
Expand Down Expand Up @@ -346,8 +359,8 @@ impl ThreadPriority {
PriorityPolicyEdgeValueType::Maximum => NICENESS_MAX as libc::c_int,
})
}
} else if #[cfg(any(target_os = "macos", target_os = "ios"))] {
// macOS/iOS allows specifying the priority using sched params.
} else if #[cfg(any(target_os = "macos", target_os = "ios", target_os = "vxworks"))] {
// macOS/iOS and VxWorks allow specifying the priority using sched params.
get_edge_priority(policy)
} else {
Err(Error::Priority(
Expand Down Expand Up @@ -426,7 +439,7 @@ impl ThreadPriority {
// for the SCHED_OTHER policy.
// <https://www.usenix.org/legacy/publications/library/proceedings/bsdcon02/full_papers/gerbarg/gerbarg_html/index.html>
#[cfg(all(
any(target_os = "macos", target_os = "ios"),
any(target_os = "macos", target_os = "ios", target_os = "vxworks"),
not(target_arch = "wasm32")
))]
ThreadSchedulePolicy::Normal(_) => {
Expand Down Expand Up @@ -571,10 +584,10 @@ pub fn set_thread_priority_and_policy(
}
_ => {
let fixed_priority = priority.to_posix(policy)?;
// On macOS and iOS it is possible to set the priority
// 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"))
|| 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.
Expand Down Expand Up @@ -613,6 +626,7 @@ pub fn set_thread_priority_and_policy(

// Normal priority threads adjust relative priority through niceness.
set_errno(0);
#[cfg(not(target_os = "vxworks"))]
let ret = unsafe { libc::setpriority(libc::PRIO_PROCESS, 0, fixed_priority) };
if ret != 0 {
return Err(Error::OS(errno()));
Expand Down

0 comments on commit bbd65de

Please sign in to comment.