From 26d47db4f922639893a8aa751fb8452723d3f711 2021-10-19 12:29:52 From: mh Date: 2021-10-19 12:29:52 Subject: [PATCH] WIP on second rewrite of port management --- diff --git a/src/runtime2/global_store.rs b/src/runtime2/global_store.rs index 018fa8e82011bd87902ced460d43bdefb7fc77ae..3b62801458e6cdc055fd273866a2f921da1e3ed0 100644 --- a/src/runtime2/global_store.rs +++ b/src/runtime2/global_store.rs @@ -138,8 +138,10 @@ impl ConnectorStore { } /// Create a new connector, returning the key that can be used to retrieve - /// and/or queue it. - pub(crate) fn create(&self, created_by: &mut ScheduledConnector, connector: ConnectorVariant) -> ConnectorKey { + /// and/or queue it. The caller must make sure that the constructed + /// connector's code is initialized with the same ports as the ports in the + /// `initial_ports` array. + pub(crate) fn create(&self, created_by: &mut ScheduledConnector, connector: ConnectorVariant, initial_ports: Vec) -> ConnectorKey { // Creation of the connector in the global store, requires a lock { let lock = self.inner.write().unwrap(); @@ -181,7 +183,6 @@ impl ConnectorStore { ConnectorVariant::UserDefined(connector) => { for port_id in &connector.ports.owned_ports { let mut port = created_by.context.remove_port(*port_id); - port.owning_connector = new_connector.context.id; new_connector.context.add_port(port); } }, diff --git a/src/runtime2/native.rs b/src/runtime2/native.rs index b0de3c54ae700703f8812d335c2397c0075f3269..04285976db5961cf363f5ff5ca65a4907151da43 100644 --- a/src/runtime2/native.rs +++ b/src/runtime2/native.rs @@ -80,7 +80,7 @@ pub struct ApplicationInterface { job_queue: JobQueue, runtime: Arc, connector_id: ConnectorId, - owned_ports: Vec, + owned_ports: Vec, } impl ApplicationInterface { @@ -99,15 +99,21 @@ impl ApplicationInterface { let putter_id = PortIdLocal::new(getter_id + 1); let getter_id = PortIdLocal::new(getter_id); - self.ports.push(Port{ + self.owned_ports.push(Port{ self_id: getter_id, peer_id: putter_id, kind: PortKind::Getter, - owning_connector: self.connector_id, peer_connector: self.connector_id, }); - return channel; + self.owned_ports.push(Port{ + self_id: putter_id, + peer_id: getter_id, + kind: PortKind::Putter, + peer_connector: self.connector_id, + }); + + return Channel{ putter_id, getter_id }; } /// Creates a new connector. Note that it is not scheduled immediately, but diff --git a/src/runtime2/port.rs b/src/runtime2/port.rs index 25cd6b3d52b59af1fcb6f0f3969b210e9dbd363a..28401fd338b82e433674f41f09ff437f93095e93 100644 --- a/src/runtime2/port.rs +++ b/src/runtime2/port.rs @@ -33,7 +33,6 @@ pub struct Port { pub self_id: PortIdLocal, pub peer_id: PortIdLocal, pub kind: PortKind, - pub owning_connector: ConnectorId, pub peer_connector: ConnectorId, // might be temporarily inconsistent while peer port is sent around in non-sync phase. } diff --git a/src/runtime2/scheduler.rs b/src/runtime2/scheduler.rs index efbc77c9238a171452b8f6c5708f021ae5350bff..233e0c0c7c0b02205d8b021eff89ef8010d7d50c 100644 --- a/src/runtime2/scheduler.rs +++ b/src/runtime2/scheduler.rs @@ -29,7 +29,7 @@ impl ConnectorCtx { Self{ id: ConnectorId::new_invalid(), port_counter, - ports: Vec::new(), + ports: initial_ports, } } @@ -44,7 +44,6 @@ impl ConnectorCtx { self_id: getter_id, peer_id: putter_id, kind: PortKind::Getter, - owning_connector: self.id, peer_connector: self.id, }); @@ -52,7 +51,6 @@ impl ConnectorCtx { self_id: putter_id, peer_id: getter_id, kind: PortKind::Putter, - owning_connector: self.id, peer_connector: self.id, });