diff --git a/src/runtime2/component/mod.rs b/src/runtime2/component/mod.rs index 5c92219776421421c209667fb96bfad54503828a..a7f2b521f7d3c51c08b6a9feae8d61fd27e36520 100644 --- a/src/runtime2/component/mod.rs +++ b/src/runtime2/component/mod.rs @@ -3,4 +3,23 @@ mod control_layer; mod consensus; pub(crate) use component_pdl::{CompPDL, CompCtx, CompScheduling}; -pub(crate) use control_layer::{ControlId}; \ No newline at end of file +pub(crate) use control_layer::{ControlId}; + +use super::scheduler::*; +use super::runtime::*; + +/// If the component is sleeping, then that flag will be atomically set to +/// false. If we're the ones that made that happen then we add it to the work +/// queue. +pub(crate) fn wake_up_if_sleeping(sched_ctx: &SchedulerCtx, comp_id: CompId, handle: &CompHandle) { + use std::sync::atomic::Ordering; + + let should_wake_up = handle.sleeping + .compare_exchange(true, false, Ordering::AcqRel, Ordering::Acquire) + .is_ok(); + + if should_wake_up { + let comp_key = unsafe{ comp_id.upgrade() }; + sched_ctx.runtime.enqueue_work(comp_key); + } +} \ No newline at end of file