diff --git a/src/runtime2/runtime.rs b/src/runtime2/runtime.rs index bf6a9baed2d0680b331672d0fcfd60f5328d2cbf..24844a612a6856a7090dc72c3948aeae6e1626b8 100644 --- a/src/runtime2/runtime.rs +++ b/src/runtime2/runtime.rs @@ -3,11 +3,12 @@ use std::sync::atomic::{AtomicU32, AtomicBool, Ordering}; use std::collections::VecDeque; use crate::protocol::*; +use crate::runtime2::component::wake_up_if_sleeping; use super::communication::Message; use super::component::{CompCtx, CompPDL}; use super::store::{ComponentStore, QueueDynMpsc, QueueDynProducer}; -use super::scheduler::Scheduler; +use super::scheduler::*; // ----------------------------------------------------------------------------- // Component @@ -58,7 +59,7 @@ pub(crate) struct RuntimeComp { pub(crate) struct CompPublic { pub sleeping: AtomicBool, pub num_handles: AtomicU32, // manually modified (!) - pub inbox: QueueDynProducer, + inbox: QueueDynProducer, } /// Handle to public part of a component. Would be nice if we could @@ -67,19 +68,29 @@ pub(crate) struct CompPublic { /// code to make sure this actually happens. pub(crate) struct CompHandle { target: *const CompPublic, + id: CompId, // TODO: @Remove after debugging #[cfg(debug_assertions)] decremented: bool, } impl CompHandle { - fn new(public: &CompPublic) -> CompHandle { + fn new(id: CompId, public: &CompPublic) -> CompHandle { let handle = CompHandle{ target: public, + id, #[cfg(debug_assertions)] decremented: false, }; handle.increment_users(); return handle; } + pub(crate) fn send_message(&self, sched_ctx: &SchedulerCtx, message: Message, try_wake_up: bool) { + sched_ctx.log(&format!("Sending message to [c:{:03}, wakeup:{}]: {:?}", self.id.0, try_wake_up, message)); + self.inbox.push(message); + if try_wake_up { + wake_up_if_sleeping(sched_ctx, self.id, self); + } + } + fn increment_users(&self) { let old_count = self.num_handles.fetch_add(1, Ordering::AcqRel); debug_assert!(old_count > 0); // because we should never be able to retrieve a handle when the component is (being) destroyed @@ -100,6 +111,7 @@ impl Clone for CompHandle { self.increment_users(); return CompHandle{ target: self.target, + id: self.id, #[cfg(debug_assertions)] decremented: false, }; } @@ -230,7 +242,7 @@ impl RuntimeInner { pub(crate) fn get_component_public(&self, id: CompId) -> CompHandle { let component = self.components.get(id.0); - return CompHandle::new(&component.public); + return CompHandle::new(id, &component.public); } pub(crate) fn destroy_component(&self, key: CompKey) {