Skip to content

Commit

Permalink
rawlist use fix: must use an unique &T as rawlist node
Browse files Browse the repository at this point in the history
Signed-off-by: guoweikang <[email protected]>
  • Loading branch information
guoweikang committed Oct 25, 2024
1 parent 9118688 commit b6cb9f7
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions modules/axtask/src/wait_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ use linked_list_r4l::{def_node, RawList};

use crate::{current_run_queue, select_run_queue, AxTaskRef};

#[cfg(feature = "irq")]
use crate::CurrentTask;

def_node! {
pub(crate) struct WaitTaskNode(AxTaskRef);
}
Expand Down Expand Up @@ -55,9 +52,10 @@ impl WaitQueue {
}
}

/// Cancel events by removing the task from the wait queue.
/// Cancel events by removing the task from the wait queue.
/// If `from_timer_list` is true, try to remove the task from the timer list.
fn cancel_events(&self, waiter: WaitTaskNode, _from_timer_list: bool) {
fn cancel_events(&self, waiter: &WaitTaskNode, _from_timer_list: bool) {
// SAFETY:
// Waiter is only defined in the local function scope,
// therefore, it is not possible in other List.
Expand All @@ -69,7 +67,7 @@ impl WaitQueue {
// Just mark task's current timer ticket ID as expired.
#[cfg(feature = "irq")]
if _from_timer_list {
waiter.into_inner().timer_ticket_expired();
waiter.inner().timer_ticket_expired();
// Note:
// this task is still not removed from timer list of target CPU,
// which may cause some redundant timer events because it still needs to
Expand All @@ -81,8 +79,8 @@ impl WaitQueue {
/// Blocks the current task and put it into the wait queue, until other task
/// notifies it.
pub fn wait(&self) {
let waiter = WaitTaskNode::from_current();
current_run_queue::<NoPreemptIrqSave>().blocked_resched(self.list.lock(), &waiter);
let waiter = &WaitTaskNode::from_current();
current_run_queue::<NoPreemptIrqSave>().blocked_resched(self.list.lock(), waiter);
self.cancel_events(waiter, false);
}

Expand All @@ -95,14 +93,14 @@ impl WaitQueue {
where
F: Fn() -> bool,
{
let waiter = WaitTaskNode::from_current();
let waiter = &WaitTaskNode::from_current();
loop {
let mut rq = current_run_queue::<NoPreemptIrqSave>();
let wq = self.list.lock();
if condition() {
break;
}
rq.blocked_resched(wq, &waiter);
rq.blocked_resched(wq, waiter);
// Preemption may occur here.
}

Expand All @@ -113,7 +111,7 @@ impl WaitQueue {
/// notify it, or the given duration has elapsed.
#[cfg(feature = "irq")]
pub fn wait_timeout(&self, dur: core::time::Duration) -> bool {
let waiter = WaitTaskNode::from_current();
let waiter = &WaitTaskNode::from_current();
let mut rq = current_run_queue::<NoPreemptIrqSave>();
let curr = crate::current();
let deadline = axhal::time::wall_time() + dur;
Expand All @@ -124,7 +122,7 @@ impl WaitQueue {
);
crate::timers::set_alarm_wakeup(deadline, curr.clone());

rq.blocked_resched(self.list.lock(), &waiter);
rq.blocked_resched(self.list.lock(), waiter);

let timeout = axhal::time::wall_time() >= deadline;

Expand All @@ -143,7 +141,7 @@ impl WaitQueue {
where
F: Fn() -> bool,
{
let waiter = WaitTaskNode::from_current();
let waiter = &WaitTaskNode::from_current();
let curr = crate::current();
let deadline = axhal::time::wall_time() + dur;
debug!(
Expand All @@ -159,12 +157,12 @@ impl WaitQueue {
if axhal::time::wall_time() >= deadline {
break;
}
let mut wq = self.list.lock();
let wq = self.list.lock();
if condition() {
timeout = false;
break;
}
rq.blocked_resched(wq, &waiter);
rq.blocked_resched(wq, waiter);
// Preemption may occur here.
}

Expand Down

0 comments on commit b6cb9f7

Please sign in to comment.