From 90051c141c8f7cc9e90c2751888a1fc94fabc3be Mon Sep 17 00:00:00 2001 From: Rod Kay Date: Wed, 4 Sep 2024 20:02:10 +1000 Subject: [PATCH] lace.event_connector.destruct: Wait til all connectors are idle before exiting. --- .../source/events/lace-event_connector.adb | 54 ++++++++++++++----- .../source/events/lace-event_connector.ads | 8 ++- 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/1-base/lace/source/events/lace-event_connector.adb b/1-base/lace/source/events/lace-event_connector.adb index 6abbccc..82806de 100644 --- a/1-base/lace/source/events/lace-event_connector.adb +++ b/1-base/lace/source/events/lace-event_connector.adb @@ -134,37 +134,48 @@ is is use ada.Text_IO; - the_Connectors : aliased safe_Connectors; + all_Connectors : connector_Vector; + idle_Connectors : aliased safe_Connectors; the_Connections : safe_Connections_view; new_Connections : connection_Vector; Done : Boolean := False; + function all_Connectors_are_idle return Boolean + is + Result : Boolean := True; + begin + for Each of all_Connectors + loop + if not Each'Callable + then + Result := False; + exit; + end if; + end loop; + + return Result; + end all_Connectors_are_idle; + + procedure shutdown is procedure free is new ada.unchecked_Deallocation (Connector, Connector_view); the_Connector : Connector_view; begin + for Each of all_Connectors loop - the_Connectors.get (the_Connector); - exit when the_Connector = null; - + the_Connector := Each; free (the_Connector); end loop; end shutdown; begin - ada.text_io.put_Line ("KKK0"); - accept start (Connections : in safe_Connections_view) do - ada.text_io.put_Line ("KKK2"); - the_Connections := Connections; - ada.text_io.put_Line ("KKK3"); - end start; @@ -191,16 +202,17 @@ is use lace.Text; the_Connector : Connector_view; begin - the_Connectors.get (the_Connector); + idle_Connectors.get (the_Connector); if the_Connector = null then the_Connector := new Connector; + all_Connectors.append (the_Connector); end if; the_Connector.connect (Self => the_Connector, the_Connection => each_Connection, - Connectors => the_Connectors'unchecked_Access); + Connectors => idle_Connectors'unchecked_Access); exception when E : others => new_Line; @@ -221,6 +233,13 @@ is delay 0.001; -- Keep task from churning when idle. end loop; + + while not all_Connectors_are_idle + loop + delay 0.001; + end loop; + + shutdown; exception @@ -375,4 +394,15 @@ is end disconnect; + + + -- function is_Busy (Self : in Item) return Boolean + -- is + -- begin + -- return false; + -- -- return not ( Self.Connections.is_Empty + -- -- and Self.Delegator .active_Count = 0); + -- end is_Busy; + + end lace.event_Connector; diff --git a/1-base/lace/source/events/lace-event_connector.ads b/1-base/lace/source/events/lace-event_connector.ads index ef51f99..2620cdf 100644 --- a/1-base/lace/source/events/lace-event_connector.ads +++ b/1-base/lace/source/events/lace-event_connector.ads @@ -12,6 +12,9 @@ with package lace.event_Connector +-- +-- +-- is type Item is tagged limited private; @@ -31,6 +34,9 @@ is to_Event_Kind : in Event.Kind; subject_Name : in String); + -- function is_Busy (Self : in Item) return Boolean; + + private @@ -79,7 +85,7 @@ private procedure add (new_Connection : in Connection); procedure get (the_Connections : out connection_Vector); - function is_Empty return Boolean; + function is_Empty return Boolean; private all_Connections : connection_Vector;