[Ada] A task not executing an entry call consumes an Entry_Call slot
This patch resolves the issue where the ATC Level of a task's first
Entry_Call slot corresponds to a task not currently making an entry
call. Consequently, the first slot is never used to record an entry
call. To resolve this, the ATC Level of a such a task is now one less
than the first index of the Entry_Call array (and as result, the ATC
level corresponding to a completed task is now two less than the first
index of this array).
To aid the maintainability of code using ATC levels new constants are
introduced to represent key ATC nesting levels and comments are
introduce for the ATC level definitions.
As a result of this change, the GNAT Extended Ravenscar Profile now
works with the full runtime. The restricted runtime had assumed that the
first Entry_Call slot would be the only slot used for entry calls and
would only initialise this slot (and
System.Tasking.Protected_Objects.Single_Entry was coded this way).
However, Extended Ravenscar uses the native implementation of
System.Tasking.Protected_Objects where this assumption doesn't hold
until the implementation of this patch. Aside from enabling an extra
nested level, this is main functional change of this patch.
The following should compile and execute quietly:
gprbuild -q main.adb
./main
-- main.adb
pragma Profile (GNAT_Extended_Ravenscar);
pragma Partition_Elaboration_Policy (Sequential);
with Tasks;
with GNAT.OS_Lib;
with Ada.Synchronous_Task_Control;
procedure Main is
pragma Priority (30);
begin
Ada.Synchronous_Task_Control.Suspend_Until_True (Tasks.A_SO);
Ada.Synchronous_Task_Control.Suspend_Until_True (Tasks.B_SO);
GNAT.OS_Lib.OS_Exit (0);
end Main;
-- tasks.ads
with Ada.Synchronous_Task_Control;
package Tasks is
A_SO : Ada.Synchronous_Task_Control.Suspension_Object;
B_SO : Ada.Synchronous_Task_Control.Suspension_Object;
task A with Priority => 25;
task B with Priority => 20;
end Tasks;
-- tasks.adb
with Obj;
package body Tasks is
task body A is
begin
for J in 1 .. 5 loop
Obj.PO.Wait;
end loop;
Ada.Synchronous_Task_Control.Set_True (Tasks.A_SO);
end A;
task body B is
begin
for J in 1 .. 5 loop
Obj.PO.Put;
end loop;
Ada.Synchronous_Task_Control.Set_True (Tasks.B_SO);
end B;
end Tasks;
-- obj.ads
package Obj is
protected type PT is
pragma Priority (30);
entry Put;
entry Wait;
private
Wait_Ready : Boolean := False;
Put_Ready : Boolean := True;
end PT;
PO : PT;
end Obj;
-- obj.adb
package body Obj is
protected body PT is
entry Put when Put_Ready is
begin
Wait_Ready := True;
Put_Ready := False;
end Put;
entry Wait when Wait_Ready is
begin
Wait_Ready := False;
Put_Ready := True;
end Wait;
end PT;
end Obj;
2018-12-03 Patrick Bernardi <bernardi@adacore.com>
gcc/ada/
* libgnarl/s-taskin.ads (ATC_Level_Base): Redefine to span from
-1 to Max_ATC_Nesting so that 0 represents no ATC nesting and -1
represented a completed task. To increase readability, new
constants are introduced to represent key ATC nesting levels.
Consequently, Level_No_Pending_Abort replaces
ATC_Level_Infinity. ATC_Level related definitions now
documented.
(Ada_Task_Control_Block): The default initialization of
components ATC_Nesting_Level and Pending_ATC_Level now use new
ATC_Level_Base constants. Comments improved
* libgnarl/s-taskin.adb (Initialize): Improve the initialisation
of the first element of the Entry_Calls array to facilitate
better maintenance.
* libgnarl/s-taasde.ads: Update comment.
* libgnarl/s-taasde.adb, libgnarl/s-taenca.adb,
libgnarl/s-tasren.adb, libgnarl/s-tassta.adb,
libgnarl/s-tasuti.ads, libgnarl/s-tasuti.adb: Use new
ATC_Level_Base constants.
* libgnarl/s-tarest.adb (Create_Restricted_Task): Improve the
initialisation of the first element of the task's Entry_Calls
array to facilitate better maintenance.
* libgnarl/s-tasini.ads (Locked_Abort_To_Level): Update
signature to accept ATC_Level_Base.
* libgnarl/s-tasini.adb (Locked_Abort_To_Level): Update
signature to accept ATC_Level_Base. Use new ATC_Level_Base
constants and only modify the aborting task's Entry_Calls array
if any entry call is happening.
* libgnarl/s-tposen.adb (Protected_Single_Entry_Call): Reference
the first element of the task's Entry_Calls array via 'First
attribute to facilitate better maintenance.
From-SVN: r266752
14 files changed: