perf: wake promptly while cooperative source tasks remain runnable
Verify Tessera GUI / verify (push) Failing after 9m31s
Verify Tessera GUI / verify (push) Failing after 9m31s
This commit is contained in:
+23
-4
@@ -1,7 +1,10 @@
|
||||
//! Owner-managed asynchronous work. Only weak identities enter the scheduler;
|
||||
//! callbacks and scopes are ordinary traced edges in the Aster object graph.
|
||||
use std::{
|
||||
sync::{Arc, Mutex},
|
||||
sync::{
|
||||
Arc, Mutex,
|
||||
atomic::{AtomicBool, Ordering},
|
||||
},
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
@@ -215,6 +218,7 @@ struct After {
|
||||
provider: crate::io_tasks::Provider,
|
||||
signature: endor_core::CallSignature,
|
||||
index: Index,
|
||||
runnable: Arc<AtomicBool>,
|
||||
desktop: ObjectRef,
|
||||
}
|
||||
impl NativeCallable for After {
|
||||
@@ -407,6 +411,9 @@ impl NativeCallable for After {
|
||||
live.retain(|old| Some(*old) != previous_weak);
|
||||
live.push(weak);
|
||||
*index = live;
|
||||
if self.operation == Operation::Spawn {
|
||||
self.runnable.store(true, Ordering::Release);
|
||||
}
|
||||
Ok(NativeResult::Return(Value::Object(task)))
|
||||
}
|
||||
}
|
||||
@@ -512,10 +519,14 @@ impl NativeCallable for Method {
|
||||
|
||||
pub struct Scheduler {
|
||||
index: Index,
|
||||
runnable: Arc<AtomicBool>,
|
||||
desktop: ObjectRef,
|
||||
provider: crate::io_tasks::Provider,
|
||||
}
|
||||
impl Scheduler {
|
||||
pub fn has_cooperative_work(&self) -> bool {
|
||||
self.runnable.load(Ordering::Acquire)
|
||||
}
|
||||
/// Mutation boundaries collect unreachable owner/callback cycles before
|
||||
/// this weak lookup. Idle timer polling does not rescan the entire heap.
|
||||
pub fn poll(&self, vm: &mut Vm, limit: usize) -> Result<usize> {
|
||||
@@ -679,6 +690,7 @@ impl Scheduler {
|
||||
.map_err(|_| anyhow::anyhow!("task index poisoned"))?;
|
||||
let count = index.len();
|
||||
index.clear();
|
||||
self.runnable.store(false, Ordering::Release);
|
||||
Ok(count)
|
||||
}
|
||||
fn prune(&self, vm: &mut Vm) -> Result<()> {
|
||||
@@ -687,11 +699,14 @@ impl Scheduler {
|
||||
.lock()
|
||||
.map_err(|_| anyhow::anyhow!("task index poisoned"))?;
|
||||
let mut live = Vec::new();
|
||||
let mut runnable = false;
|
||||
for weak in index.iter().copied() {
|
||||
if let Some(task) = vm.upgrade(weak)? {
|
||||
let pending = vm
|
||||
.payload::<Task>(task, "Task")
|
||||
.map(|task| matches!(task.state, State::Pending | State::Running));
|
||||
let pending = vm.payload::<Task>(task, "Task").map(|task| {
|
||||
let pending = matches!(task.state, State::Pending | State::Running);
|
||||
runnable |= pending && task.cooperative;
|
||||
pending
|
||||
});
|
||||
vm.release(task)?;
|
||||
if pending? {
|
||||
live.push(weak);
|
||||
@@ -699,6 +714,7 @@ impl Scheduler {
|
||||
}
|
||||
}
|
||||
*index = live;
|
||||
self.runnable.store(runnable, Ordering::Release);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -815,6 +831,7 @@ pub fn install(
|
||||
desktop: ObjectRef,
|
||||
) -> Result<Scheduler> {
|
||||
let index = Arc::new(Mutex::new(Vec::new()));
|
||||
let runnable = Arc::new(AtomicBool::new(false));
|
||||
let definition = desktop_type(vm.object_store(), "Task", desktop)?;
|
||||
let provider = crate::io_tasks::Provider::default();
|
||||
for (name, operation) in [
|
||||
@@ -858,6 +875,7 @@ pub fn install(
|
||||
signature
|
||||
},
|
||||
index: index.clone(),
|
||||
runnable: runnable.clone(),
|
||||
desktop,
|
||||
},
|
||||
vec![desktop],
|
||||
@@ -898,6 +916,7 @@ pub fn install(
|
||||
}
|
||||
Ok(Scheduler {
|
||||
index,
|
||||
runnable,
|
||||
desktop,
|
||||
provider,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user