pr7.7
This commit is contained in:
@@ -305,6 +305,25 @@ impl Heap {
|
||||
/// Current number of allocated (live) objects.
|
||||
pub fn len(&self) -> usize { self.objects.iter().filter(|s| s.is_some()).count() }
|
||||
pub fn is_empty(&self) -> bool { self.len() == 0 }
|
||||
|
||||
/// Enumerate handles of coroutines that are currently suspended (i.e., not running):
|
||||
/// Ready or Sleeping. These must be treated as GC roots by the runtime so their
|
||||
/// stacks/frames are scanned during mark.
|
||||
pub fn suspended_coroutine_handles(&self) -> Vec<HeapRef> {
|
||||
let mut out = Vec::new();
|
||||
for (idx, slot) in self.objects.iter().enumerate() {
|
||||
if let Some(obj) = slot {
|
||||
if obj.header.kind == ObjectKind::Coroutine {
|
||||
if let Some(co) = &obj.coroutine {
|
||||
if matches!(co.state, CoroutineState::Ready | CoroutineState::Sleeping) {
|
||||
out.push(HeapRef(idx as u32));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user