diff --git a/src/runtime2/global_store.rs b/src/runtime2/global_store.rs index 96a30954aeedf71e9f3684d89b0cef2550aff4b1..e71494f58f910e269179d5e47fbdfd28cffca18b 100644 --- a/src/runtime2/global_store.rs +++ b/src/runtime2/global_store.rs @@ -1,6 +1,6 @@ use crate::collections::{MpmcQueue, RawVec}; -use super::connector::{Connector, ConnectorPublic}; +use super::connector::{ConnectorPDL, ConnectorPublic}; use super::port::{PortIdLocal, Port, PortKind, PortOwnership, Channel}; use super::inbox::PublicInbox; use super::scheduler::Router; @@ -8,6 +8,7 @@ use super::scheduler::Router; use std::ptr; use std::sync::{Barrier, RwLock, RwLockReadGuard}; use std::sync::atomic::AtomicBool; +use crate::runtime2::native::Connector; /// A kind of token that, once obtained, allows mutable access to a connector. /// We're trying to use move semantics as much as possible: the owner of this @@ -45,8 +46,15 @@ impl ConnectorId { } } +// TODO: Change this, I hate this. But I also don't want to put `public` and +// `router` of `ScheduledConnector` back into `Connector`. +pub enum ConnectorVariant { + UserDefined(ConnectorPDL), + Native(Box), +} + pub struct ScheduledConnector { - pub connector: Connector, + pub connector: ConnectorVariant, pub public: ConnectorPublic, pub router: Router } @@ -100,7 +108,7 @@ impl ConnectorStore { /// Create a new connector, returning the key that can be used to retrieve /// and/or queue it. - pub(crate) fn create(&self, connector: Connector) -> ConnectorKey { + pub(crate) fn create(&self, connector: ConnectorVariant) -> ConnectorKey { let lock = self.inner.write().unwrap(); let connector = ScheduledConnector{ connector, @@ -189,17 +197,12 @@ impl PortStore { } } - pub(crate) fn create_channel(&self, creating_connector: Option) -> Channel { + pub(crate) fn create_channel(&self, creating_connector: ConnectorId) -> Channel { let mut lock = self.inner.write().unwrap(); // Reserves a new port. Doesn't point it to its counterpart - fn reserve_port(lock: &mut std::sync::RwLockWriteGuard<'_, PortStoreInner>, kind: PortKind, creating_connector: Option) -> u32 { + fn reserve_port(lock: &mut std::sync::RwLockWriteGuard<'_, PortStoreInner>, kind: PortKind, creating_connector: ConnectorId) -> u32 { let index; - let (ownership, connector_id) = if creating_connector.is_some() { - (PortOwnership::Owned, creating_connector.unwrap()) - } else { - (PortOwnership::Unowned, ConnectorId::new_invalid()) - }; if lock.free.is_empty() { index = lock.ports.len() as u32; @@ -207,7 +210,7 @@ impl PortStore { self_id: PortIdLocal::new(index), peer_id: PortIdLocal::new_invalid(), kind, - ownership, + ownership: PortOwnership::Owned, owning_connector: connector_id, peer_connector: connector_id }); @@ -217,7 +220,7 @@ impl PortStore { port.peer_id = PortIdLocal::new_invalid(); port.kind = kind; - port.ownership = ownership; + port.ownership = PortOwnership::Owned; port.owning_connector = connector_id; port.peer_connector = connector_id; } @@ -238,7 +241,10 @@ impl PortStore { getter_port.peer_id = putter_port.self_id; } - return Channel{ putter_id, getter_id } + return Channel{ + putter_id: PortIdLocal::new(putter_id), + getter_id: PortIdLocal::new(getter_id), + } } }