On 2018-08-04 04:03, Jeremiah Breeden wrote:
> Ok, with that in mind, the current set of loops are not being done
> atomically (it is not done inside a protected operation). So the next
> question is how do we get to where they are done in a more atomic
> manner. I started off with a mutex like implementation for the close
> loop.since the close procedure could potentially block (and thus could
> not go in a protected operation). That wouldn't work for the ping
> loop without restructuring the ping procedure itself (and pull out the
> deletions to be done afterwards as mentioned in an earlier email/post).
>
At work, we sometimes (when tasking) use the pattern below.
At the end there is a client package with procedures A and B which both
may affect the same resourse.
But both start with grabbing a common semaphore which
will be autmatically released when out of scoope.
This way we use the same protected object but with no blocking
operations in it.
But this is perhaps what you meant with mutex operation?
There are packages Semaphores and Semaphores.Controls to enable this.
----------------------------------------------
package Semaphores is
protected type Semaphore_Type is
------------------------
procedure Release;
------------------------
entry Seize;
------------------------
private
In_Use : Boolean := False;
end Semaphore_Type;
end Semaphores;
----------------------------------------------
package body Semaphores is
protected body Semaphore_Type is
------------------------
procedure Release is
begin
In_Use := False;
end Release;
------------------------
entry Seize when not In_Use is
begin
In_Use := True;
end Seize;
------------------------
end Semaphore_Type;
end Semaphores;
----------------------------------------------
with Ada.Finalization;
package Semaphores.Controls is
pragma Preelaborate;
type Semaphore_Control (Semaphore : access Semaphore_Type) is limited
private;
private
use Ada.Finalization;
type Semaphore_Control (Semaphore : access Semaphore_Type) is
new Limited_Controlled with null record;
procedure Initialize (Control : in out Semaphore_Control);
procedure Finalize (Control : in out Semaphore_Control);
end Semaphores.Controls;
----------------------------------------------
package body Semaphores.Controls is
procedure Initialize (Control : in out Semaphore_Control) is
begin
Control.Semaphore.Seize;
end Initialize;
procedure Finalize (Control : in out Semaphore_Control) is
begin
Control.Semaphore.Release;
end Finalize;
end Semaphores.Controls;
----------------------------------------------
with Semaphores; use Semaphores;
with_Semaphores.Controls; use Semaphores.Controls;
package body client is
Semaphore : aliased Semaphore_Type;
----------------------
procedure A is
Control : Semaphore_Control (Semaphore'access);
pragma Warnings(Off, Control);
begin
Do_Stuff_1;
end A;
----------------------
procedure B is
Control : Semaphore_Control (Semaphore'access);
pragma Warnings(Off, Control);
begin
Do_Stuff_2;
end B;
end client;
--
--
Björn
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Gnoga-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gnoga-list