Skip to content

Commit

Permalink
Rollup merge of rust-lang#106372 - joboet:solid_id_parking, r=m-ou-se
Browse files Browse the repository at this point in the history
Use id-based thread parking on SOLID

By using the [`slp_tsk`/`wup_tsk`](https://cs.uwaterloo.ca/~brecht/courses/702/Possible-Readings/embedded/uITRON-4.0-specification.pdf) system functions instead of an event-flag structure, `Parker` becomes cheaper to construct and SOLID can share the implementation used by NetBSD and SGX.

ping `@kawadakk`
r? `@m-ou-se`
`@rustbot` label +T-libs
  • Loading branch information
Dylan-DPC authored Feb 14, 2023
2 parents 86368ae + 7824528 commit 6f88493
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 179 deletions.
37 changes: 37 additions & 0 deletions library/std/src/sys/itron/thread_parking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use super::abi;
use super::error::expect_success_aborting;
use super::time::with_tmos;
use crate::time::Duration;

pub type ThreadId = abi::ID;

pub use super::task::current_task_id_aborting as current;

pub fn park(_hint: usize) {
match unsafe { abi::slp_tsk() } {
abi::E_OK | abi::E_RLWAI => {}
err => {
expect_success_aborting(err, &"slp_tsk");
}
}
}

pub fn park_timeout(dur: Duration, _hint: usize) {
match with_tmos(dur, |tmo| unsafe { abi::tslp_tsk(tmo) }) {
abi::E_OK | abi::E_RLWAI | abi::E_TMOUT => {}
err => {
expect_success_aborting(err, &"tslp_tsk");
}
}
}

pub fn unpark(id: ThreadId, _hint: usize) {
match unsafe { abi::wup_tsk(id) } {
// It is allowed to try to wake up a destroyed or unrelated task, so we ignore all
// errors that could result from that situation.
abi::E_OK | abi::E_NOEXS | abi::E_OBJ | abi::E_QOVR => {}
err => {
expect_success_aborting(err, &"wup_tsk");
}
}
}
72 changes: 0 additions & 72 deletions library/std/src/sys/itron/wait_flag.rs

This file was deleted.

4 changes: 2 additions & 2 deletions library/std/src/sys/solid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ mod itron {
pub(super) mod spin;
pub(super) mod task;
pub mod thread;
pub mod thread_parking;
pub(super) mod time;
use super::unsupported;
pub mod wait_flag;
}

pub mod alloc;
Expand Down Expand Up @@ -43,8 +43,8 @@ pub use self::itron::thread;
pub mod memchr;
pub mod thread_local_dtor;
pub mod thread_local_key;
pub use self::itron::thread_parking;
pub mod time;
pub use self::itron::wait_flag;

mod rwlock;

Expand Down
4 changes: 1 addition & 3 deletions library/std/src/sys_common/thread_parking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ cfg_if::cfg_if! {
} else if #[cfg(any(
target_os = "netbsd",
all(target_vendor = "fortanix", target_env = "sgx"),
target_os = "solid_asp3",
))] {
mod id;
pub use id::Parker;
} else if #[cfg(target_os = "solid_asp3")] {
mod wait_flag;
pub use wait_flag::Parker;
} else if #[cfg(any(windows, target_family = "unix"))] {
pub use crate::sys::thread_parking::Parker;
} else {
Expand Down
102 changes: 0 additions & 102 deletions library/std/src/sys_common/thread_parking/wait_flag.rs

This file was deleted.

0 comments on commit 6f88493

Please sign in to comment.