1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- A D A . T A S K _ T E R M I N A T I O N --
9 -- Copyright (C) 2005-2020, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
33 with System
.Task_Primitives
.Operations
;
34 with System
.Soft_Links
;
36 with Ada
.Unchecked_Conversion
;
38 package body Ada
.Task_Termination
is
40 use type Ada
.Task_Identification
.Task_Id
;
42 package STPO
renames System
.Task_Primitives
.Operations
;
43 package SSL
renames System
.Soft_Links
;
45 -----------------------
46 -- Local subprograms --
47 -----------------------
49 function To_TT
is new Ada
.Unchecked_Conversion
50 (System
.Tasking
.Termination_Handler
, Termination_Handler
);
52 function To_ST
is new Ada
.Unchecked_Conversion
53 (Termination_Handler
, System
.Tasking
.Termination_Handler
);
55 function To_Task_Id
is new Ada
.Unchecked_Conversion
56 (Ada
.Task_Identification
.Task_Id
, System
.Tasking
.Task_Id
);
58 -----------------------------------
59 -- Current_Task_Fallback_Handler --
60 -----------------------------------
62 function Current_Task_Fallback_Handler
return Termination_Handler
is
64 -- There is no need for explicit protection against race conditions
65 -- for this function because this function can only be executed by
66 -- Self, and the Fall_Back_Handler can only be modified by Self.
68 return To_TT
(STPO
.Self
.Common
.Fall_Back_Handler
);
69 end Current_Task_Fallback_Handler
;
71 -------------------------------------
72 -- Set_Dependents_Fallback_Handler --
73 -------------------------------------
75 procedure Set_Dependents_Fallback_Handler
76 (Handler
: Termination_Handler
)
78 Self
: constant System
.Tasking
.Task_Id
:= STPO
.Self
;
82 STPO
.Write_Lock
(Self
);
84 Self
.Common
.Fall_Back_Handler
:= To_ST
(Handler
);
87 SSL
.Abort_Undefer
.all;
88 end Set_Dependents_Fallback_Handler
;
90 --------------------------
91 -- Set_Specific_Handler --
92 --------------------------
94 procedure Set_Specific_Handler
95 (T
: Ada
.Task_Identification
.Task_Id
;
96 Handler
: Termination_Handler
)
99 -- Tasking_Error is raised if the task identified by T has already
100 -- terminated. Program_Error is raised if the value of T is
103 if T
= Ada
.Task_Identification
.Null_Task_Id
then
105 elsif Ada
.Task_Identification
.Is_Terminated
(T
) then
109 Target
: constant System
.Tasking
.Task_Id
:= To_Task_Id
(T
);
113 STPO
.Write_Lock
(Target
);
115 Target
.Common
.Specific_Handler
:= To_ST
(Handler
);
117 STPO
.Unlock
(Target
);
118 SSL
.Abort_Undefer
.all;
121 end Set_Specific_Handler
;
123 ----------------------
124 -- Specific_Handler --
125 ----------------------
127 function Specific_Handler
128 (T
: Ada
.Task_Identification
.Task_Id
) return Termination_Handler
131 -- Tasking_Error is raised if the task identified by T has already
132 -- terminated. Program_Error is raised if the value of T is
135 if T
= Ada
.Task_Identification
.Null_Task_Id
then
137 elsif Ada
.Task_Identification
.Is_Terminated
(T
) then
141 Target
: constant System
.Tasking
.Task_Id
:= To_Task_Id
(T
);
142 TH
: Termination_Handler
;
146 STPO
.Write_Lock
(Target
);
148 TH
:= To_TT
(Target
.Common
.Specific_Handler
);
150 STPO
.Unlock
(Target
);
151 SSL
.Abort_Undefer
.all;
156 end Specific_Handler
;
158 end Ada
.Task_Termination
;