Skip to content

Commit

Permalink
fixup! refactor(threads): avoid unnecessary scheduler invocations
Browse files Browse the repository at this point in the history
Apply suggestions from code review

Co-authored-by: ROMemories <152802150+ROMemories@users.noreply.github.com>
  • Loading branch information
elenaf9 and ROMemories authored Oct 10, 2024
1 parent 3969415 commit 2bb11bc
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/riot-rs-threads/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl Threads {
self.runqueue.add(pid, prio);
self.schedule_if_higher_prio(pid, prio);
} else if old_state == ThreadState::Running {
// A running thread is only set into a non-running state
// A running thread is only set to a non-running state
// if it itself initiated it.
debug_assert_eq!(Some(pid), self.current_pid());

Expand Down Expand Up @@ -223,7 +223,7 @@ impl Threads {
}
thread.prio = prio;
if thread.state != ThreadState::Running {
// No runqueue changes or scheduler invocations needed.
// No runqueue changes or scheduler invocation needed.
return;
}

Expand All @@ -234,7 +234,7 @@ impl Threads {
}
self.runqueue.add(thread_id, prio);

// Check if the thread currently running and trigger the scheduler if
// Check if the thread is currently running and trigger the scheduler if
// its prio decreased and another thread might have a higher prio now.
if self.is_running(thread_id) {
if prio < old_prio {
Expand All @@ -250,7 +250,7 @@ impl Threads {
}
}

/// Trigger the scheduler if the thread has higher priority than the current running thread.
/// Triggers the scheduler if the thread has higher priority than the current running thread.
fn schedule_if_higher_prio(&mut self, _thread_id: ThreadId, prio: RunqueueId) {
match self.current().map(|t| t.prio) {
Some(curr_prio) if curr_prio < prio => schedule(),
Expand Down

0 comments on commit 2bb11bc

Please sign in to comment.