diff --git a/src/runtime2/global_store.rs b/src/runtime2/global_store.rs index 4d1727af58fd65e42030dca6e874baab875504bb..191c529907db1526c6cd6337f190724e0830e2d3 100644 --- a/src/runtime2/global_store.rs +++ b/src/runtime2/global_store.rs @@ -8,6 +8,9 @@ use super::scheduler::Router; use std::ptr; use std::sync::{Barrier, RwLock, RwLockReadGuard}; use std::sync::atomic::AtomicBool; +use crate::ProtocolDescription; +use crate::runtime2::connector::{ConnectorScheduling, RunDeltaState}; +use crate::runtime2::inbox::{DataMessage, SyncMessage}; use crate::runtime2::native::Connector; /// A kind of token that, once obtained, allows mutable access to a connector. @@ -52,16 +55,41 @@ impl ConnectorId { } // TODO: Change this, I hate this. But I also don't want to put `public` and -// `router` of `ScheduledConnector` back into `Connector`. +// `router` of `ScheduledConnector` back into `Connector`. The reason I don't +// want `Box` everywhere is because of the v-table overhead. But +// to truly design this properly I need some benchmarks. pub enum ConnectorVariant { UserDefined(ConnectorPDL), Native(Box), } +impl Connector for ConnectorVariant { + fn insert_data_message(&mut self, message: DataMessage) { + match self { + ConnectorVariant::UserDefined(c) => c.insert_data_message(message), + ConnectorVariant::Native(c) => c.insert_data_message(message), + } + } + + fn insert_sync_message(&mut self, message: SyncMessage, global: &GlobalStore, delta_state: &mut RunDeltaState) { + match self { + ConnectorVariant::UserDefined(c) => c.insert_sync_message(message, global, delta_state), + ConnectorVariant::Native(c) => c.insert_sync_message(message, global, delta_state), + } + } + + fn run(&mut self, protocol_description: &ProtocolDescription, global: &GlobalStore, delta_state: &mut RunDeltaState) -> ConnectorScheduling { + match self { + ConnectorVariant::UserDefined(c) => c.run(protocol_description, global, delta_state), + ConnectorVariant::Native(c) => c.run(protocol_description, global, delta_state), + } + } +} + pub struct ScheduledConnector { pub connector: ConnectorVariant, pub public: ConnectorPublic, - pub router: Router + pub router: Router, } /// The registry containing all connectors. The idea here is that when someone