Skip to content

Commit

Permalink
refactor(threading)!: rename parking functions to match the std's
Browse files Browse the repository at this point in the history
Keep the previous names as aliases to cater to RIOT's devs.
  • Loading branch information
ROMemories committed Jan 10, 2025
1 parent 80f2759 commit b1971cf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/ariel-os-threads/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl Scheduler {
Cpu::setup_stack(thread, stack, func, arg);
thread.prio = prio;
thread.tid = tid;
thread.state = ThreadState::Paused;
thread.state = ThreadState::Parked;
#[cfg(feature = "core-affinity")]
{
thread.core_affinity = _core_affinity.unwrap_or_default();
Expand Down Expand Up @@ -684,22 +684,24 @@ pub fn yield_same() {
}

/// Suspends/ pauses the current thread's execution.
pub fn sleep() {
#[doc(alias = "sleep")]
pub fn park() {
SCHEDULER.with_mut(|mut scheduler| {
let Some(tid) = scheduler.current_tid() else {
return;
};
scheduler.set_state(tid, ThreadState::Paused);
scheduler.set_state(tid, ThreadState::Parked);
});
}

/// Wakes up a thread and adds it to the runqueue.
///
/// Returns `false` if no paused thread exists for `thread_id`.
pub fn wakeup(thread_id: ThreadId) -> bool {
/// Returns `false` if no parked thread exists for `thread_id`.
#[doc(alias = "wakeup")]
pub fn unpark(thread_id: ThreadId) -> bool {
SCHEDULER.with_mut(|mut scheduler| {
match scheduler.get_state(thread_id) {
Some(ThreadState::Paused) => {}
Some(ThreadState::Parked) => {}
_ => return false,
}
scheduler.set_state(thread_id, ThreadState::Running);
Expand Down
2 changes: 1 addition & 1 deletion src/ariel-os-threads/src/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub enum ThreadState {
/// but rather that it is in the runqueue.
Running,
/// Suspended / paused.
Paused,
Parked,
/// Waiting to acquire a [`super::lock::Lock`].
LockBlocked,
/// Waiting for [`ThreadFlags`] to be set.
Expand Down

0 comments on commit b1971cf

Please sign in to comment.