Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.

Commit cf70394

Browse files
committed
Scheduler::is_run_queued(&Arc<ProcessControlBlock>)
Be able to check if a scheduler is still scheduling a process.
1 parent d936a74 commit cf70394

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

lumen_runtime/src/run/queues.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ pub struct Queues {
2424
}
2525

2626
impl Queues {
27+
#[cfg(test)]
28+
pub fn contains(&self, value: &Arc<ProcessControlBlock>) -> bool {
29+
self.waiting.contains(value)
30+
|| self.normal_low.contains(value)
31+
|| self.high.contains(value)
32+
|| self.max.contains(value)
33+
}
34+
2735
#[cfg(test)]
2836
pub fn run_queue_len(&self, priority: Priority) -> usize {
2937
match priority {
@@ -117,6 +125,11 @@ impl Next {
117125
pub struct Waiting(HashSet<Arc<ProcessControlBlock>>);
118126

119127
impl Waiting {
128+
#[cfg(test)]
129+
fn contains(&self, value: &Arc<ProcessControlBlock>) -> bool {
130+
self.0.contains(value)
131+
}
132+
120133
fn get<Q: ?Sized>(&self, value: &Q) -> Option<&Arc<ProcessControlBlock>>
121134
where
122135
Arc<ProcessControlBlock>: Borrow<Q>,

lumen_runtime/src/run/queues/delayed.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ use crate::run::Run;
1313
pub struct Delayed(VecDeque<DelayedProcess>);
1414

1515
impl Delayed {
16+
#[cfg(test)]
17+
pub fn contains(&self, value: &Arc<ProcessControlBlock>) -> bool {
18+
self.0
19+
.iter()
20+
.any(|delayed_process| &delayed_process.arc_process == value)
21+
}
22+
1623
pub fn len(&self) -> usize {
1724
self.0.len()
1825
}

lumen_runtime/src/run/queues/immediate.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ use crate::run::Run;
1010
pub struct Immediate(VecDeque<Arc<ProcessControlBlock>>);
1111

1212
impl Immediate {
13+
#[cfg(test)]
14+
pub fn contains(&self, value: &Arc<ProcessControlBlock>) -> bool {
15+
self.0.contains(value)
16+
}
17+
1318
pub fn len(&self) -> usize {
1419
self.0.len()
1520
}

lumen_runtime/src/scheduler.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ impl Scheduler {
184184
self.run_queues.read().run_queue_len(priority)
185185
}
186186

187+
#[cfg(test)]
188+
pub fn is_run_queued(&self, value: &Arc<ProcessControlBlock>) -> bool {
189+
self.run_queues.read().contains(value)
190+
}
191+
187192
/// Returns `true` if `arc_process` was run; otherwise, `false`.
188193
#[must_use]
189194
pub fn run_through(&self, arc_process: &Arc<ProcessControlBlock>) -> bool {

0 commit comments

Comments
 (0)