Skip to content

Commit

Permalink
Tests remove in_wait_queue and add remove assert success
Browse files Browse the repository at this point in the history
Signed-off-by: guoweikang <[email protected]>
  • Loading branch information
guoweikang committed Oct 16, 2024
1 parent c3bca20 commit 7b76e04
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 0 additions & 4 deletions modules/axtask/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ fn test_wait_queue() {
WQ1.notify_one(true); // WQ1.wait_until()
WQ2.wait();

assert!(!current().in_wait_queue());

COUNTER.fetch_sub(1, Ordering::Relaxed);
println!("wait_queue: task {:?} finished", current().id());
WQ1.notify_one(true); // WQ1.wait_until()
Expand All @@ -92,7 +90,6 @@ fn test_wait_queue() {
println!("task {:?} is waiting for tasks to start...", current().id());
WQ1.wait_until(|| COUNTER.load(Ordering::Relaxed) == NUM_TASKS);
assert_eq!(COUNTER.load(Ordering::Relaxed), NUM_TASKS);
assert!(!current().in_wait_queue());
WQ2.notify_all(true); // WQ2.wait()

println!(
Expand All @@ -101,7 +98,6 @@ fn test_wait_queue() {
);
WQ1.wait_until(|| COUNTER.load(Ordering::Relaxed) == 0);
assert_eq!(COUNTER.load(Ordering::Relaxed), 0);
assert!(!current().in_wait_queue());
}

#[test]
Expand Down
14 changes: 10 additions & 4 deletions modules/axtask/src/wait_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ impl WaitQueue {
declare_current_waiter!(waiter);
let mut rq = current_run_queue::<NoPreemptIrqSave>();
rq.blocked_resched(self.queue.lock(), waiter.clone());
self.queue.lock().remove(&waiter);
// It can only be notified, it should not be in the list
assert!(self.queue.lock().remove(&waiter).is_none());
}

/// Blocks the current task and put it into the wait queue, until the given
Expand All @@ -92,9 +93,13 @@ impl WaitQueue {
if condition() {
break;
}
// It can only be notified, it should not be in the list
assert!(wq.remove(&waiter).is_none());
rq.blocked_resched(wq, waiter.clone());
}
self.queue.lock().remove(&waiter);

// It can only be notified, it should not be in the list
assert!(self.queue.lock().remove(&waiter).is_none());
}

/// Blocks the current task and put it into the wait queue, until other tasks
Expand All @@ -117,7 +122,7 @@ impl WaitQueue {
let timeout = axhal::time::wall_time() >= deadline;

// Always try to remove the task from wait list.
self.queue.lock().remove(&waiter);
self.queue.lock().remove(&waiter).is_some();
// Always try to remove the task from the timer list.
self.cancel_timer(curr);
timeout
Expand Down Expand Up @@ -154,7 +159,8 @@ impl WaitQueue {
timeout = false;
break;
}

// It can only be notified, it should not be in the list
assert!(wq.remove(&waiter).is_none());
rq.blocked_resched(wq, waiter.clone());
}
// Always try to remove the task from wait list.
Expand Down

0 comments on commit 7b76e04

Please sign in to comment.