Skip to content

Commit 7b76e04

Browse files
committed
Tests remove in_wait_queue and add remove assert success
Signed-off-by: guoweikang <[email protected]>
1 parent c3bca20 commit 7b76e04

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

modules/axtask/src/tests.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ fn test_wait_queue() {
8181
WQ1.notify_one(true); // WQ1.wait_until()
8282
WQ2.wait();
8383

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

9895
println!(
@@ -101,7 +98,6 @@ fn test_wait_queue() {
10198
);
10299
WQ1.wait_until(|| COUNTER.load(Ordering::Relaxed) == 0);
103100
assert_eq!(COUNTER.load(Ordering::Relaxed), 0);
104-
assert!(!current().in_wait_queue());
105101
}
106102

107103
#[test]

modules/axtask/src/wait_queue.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ impl WaitQueue {
7373
declare_current_waiter!(waiter);
7474
let mut rq = current_run_queue::<NoPreemptIrqSave>();
7575
rq.blocked_resched(self.queue.lock(), waiter.clone());
76-
self.queue.lock().remove(&waiter);
76+
// It can only be notified, it should not be in the list
77+
assert!(self.queue.lock().remove(&waiter).is_none());
7778
}
7879

7980
/// Blocks the current task and put it into the wait queue, until the given
@@ -92,9 +93,13 @@ impl WaitQueue {
9293
if condition() {
9394
break;
9495
}
96+
// It can only be notified, it should not be in the list
97+
assert!(wq.remove(&waiter).is_none());
9598
rq.blocked_resched(wq, waiter.clone());
9699
}
97-
self.queue.lock().remove(&waiter);
100+
101+
// It can only be notified, it should not be in the list
102+
assert!(self.queue.lock().remove(&waiter).is_none());
98103
}
99104

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

119124
// Always try to remove the task from wait list.
120-
self.queue.lock().remove(&waiter);
125+
self.queue.lock().remove(&waiter).is_some();
121126
// Always try to remove the task from the timer list.
122127
self.cancel_timer(curr);
123128
timeout
@@ -154,7 +159,8 @@ impl WaitQueue {
154159
timeout = false;
155160
break;
156161
}
157-
162+
// It can only be notified, it should not be in the list
163+
assert!(wq.remove(&waiter).is_none());
158164
rq.blocked_resched(wq, waiter.clone());
159165
}
160166
// Always try to remove the task from wait list.

0 commit comments

Comments
 (0)