annotate gcc/ada/libgnarl/s-solita.adb @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S Y S T E M . S O F T _ L I N K S . T A S K I N G --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 2004-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 pragma Style_Checks (All_Checks);
kono
parents:
diff changeset
33 -- Turn off subprogram alpha ordering check, since we group soft link bodies
kono
parents:
diff changeset
34 -- and dummy soft link bodies together separately in this unit.
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 pragma Polling (Off);
kono
parents:
diff changeset
37 -- Turn polling off for this package. We don't need polling during any of the
kono
parents:
diff changeset
38 -- routines in this package, and more to the point, if we try to poll it can
kono
parents:
diff changeset
39 -- cause infinite loops.
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 with Ada.Exceptions;
kono
parents:
diff changeset
42 with Ada.Exceptions.Is_Null_Occurrence;
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 with System.Task_Primitives.Operations;
kono
parents:
diff changeset
45 with System.Tasking;
kono
parents:
diff changeset
46 with System.Stack_Checking;
kono
parents:
diff changeset
47 with System.Secondary_Stack;
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 package body System.Soft_Links.Tasking is
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 package STPO renames System.Task_Primitives.Operations;
kono
parents:
diff changeset
52 package SSL renames System.Soft_Links;
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 use Ada.Exceptions;
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 use type System.Secondary_Stack.SS_Stack_Ptr;
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 use type System.Tasking.Task_Id;
kono
parents:
diff changeset
59 use type System.Tasking.Termination_Handler;
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 ----------------
kono
parents:
diff changeset
62 -- Local Data --
kono
parents:
diff changeset
63 ----------------
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 Initialized : Boolean := False;
kono
parents:
diff changeset
66 -- Boolean flag that indicates whether the tasking soft links have
kono
parents:
diff changeset
67 -- already been set.
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 -----------------------------------------------------------------
kono
parents:
diff changeset
70 -- Tasking Versions of Services Needed by Non-Tasking Programs --
kono
parents:
diff changeset
71 -----------------------------------------------------------------
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 function Get_Jmpbuf_Address return Address;
kono
parents:
diff changeset
74 procedure Set_Jmpbuf_Address (Addr : Address);
kono
parents:
diff changeset
75 -- Get/Set Jmpbuf_Address for current task
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 function Get_Sec_Stack return SST.SS_Stack_Ptr;
kono
parents:
diff changeset
78 procedure Set_Sec_Stack (Stack : SST.SS_Stack_Ptr);
kono
parents:
diff changeset
79 -- Get/Set location of current task's secondary stack
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 procedure Timed_Delay_T (Time : Duration; Mode : Integer);
kono
parents:
diff changeset
82 -- Task-safe version of SSL.Timed_Delay
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 procedure Task_Termination_Handler_T (Excep : SSL.EO);
kono
parents:
diff changeset
85 -- Task-safe version of the task termination procedure
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 function Get_Stack_Info return Stack_Checking.Stack_Access;
kono
parents:
diff changeset
88 -- Get access to the current task's Stack_Info
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 --------------------------
kono
parents:
diff changeset
91 -- Soft-Link Get Bodies --
kono
parents:
diff changeset
92 --------------------------
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 function Get_Jmpbuf_Address return Address is
kono
parents:
diff changeset
95 begin
kono
parents:
diff changeset
96 return STPO.Self.Common.Compiler_Data.Jmpbuf_Address;
kono
parents:
diff changeset
97 end Get_Jmpbuf_Address;
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 function Get_Sec_Stack return SST.SS_Stack_Ptr is
kono
parents:
diff changeset
100 begin
kono
parents:
diff changeset
101 return Result : constant SST.SS_Stack_Ptr :=
kono
parents:
diff changeset
102 STPO.Self.Common.Compiler_Data.Sec_Stack_Ptr
kono
parents:
diff changeset
103 do
kono
parents:
diff changeset
104 pragma Assert (Result /= null);
kono
parents:
diff changeset
105 end return;
kono
parents:
diff changeset
106 end Get_Sec_Stack;
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 function Get_Stack_Info return Stack_Checking.Stack_Access is
kono
parents:
diff changeset
109 begin
kono
parents:
diff changeset
110 return STPO.Self.Common.Compiler_Data.Pri_Stack_Info'Access;
kono
parents:
diff changeset
111 end Get_Stack_Info;
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 --------------------------
kono
parents:
diff changeset
114 -- Soft-Link Set Bodies --
kono
parents:
diff changeset
115 --------------------------
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 procedure Set_Jmpbuf_Address (Addr : Address) is
kono
parents:
diff changeset
118 begin
kono
parents:
diff changeset
119 STPO.Self.Common.Compiler_Data.Jmpbuf_Address := Addr;
kono
parents:
diff changeset
120 end Set_Jmpbuf_Address;
kono
parents:
diff changeset
121
kono
parents:
diff changeset
122 procedure Set_Sec_Stack (Stack : SST.SS_Stack_Ptr) is
kono
parents:
diff changeset
123 begin
kono
parents:
diff changeset
124 STPO.Self.Common.Compiler_Data.Sec_Stack_Ptr := Stack;
kono
parents:
diff changeset
125 end Set_Sec_Stack;
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 -------------------
kono
parents:
diff changeset
128 -- Timed_Delay_T --
kono
parents:
diff changeset
129 -------------------
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 procedure Timed_Delay_T (Time : Duration; Mode : Integer) is
kono
parents:
diff changeset
132 Self_Id : constant System.Tasking.Task_Id := STPO.Self;
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 begin
kono
parents:
diff changeset
135 -- In case pragma Detect_Blocking is active then Program_Error
kono
parents:
diff changeset
136 -- must be raised if this potentially blocking operation
kono
parents:
diff changeset
137 -- is called from a protected operation.
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 if System.Tasking.Detect_Blocking
kono
parents:
diff changeset
140 and then Self_Id.Common.Protected_Action_Nesting > 0
kono
parents:
diff changeset
141 then
kono
parents:
diff changeset
142 raise Program_Error with "potentially blocking operation";
kono
parents:
diff changeset
143 else
kono
parents:
diff changeset
144 Abort_Defer.all;
kono
parents:
diff changeset
145 STPO.Timed_Delay (Self_Id, Time, Mode);
kono
parents:
diff changeset
146 Abort_Undefer.all;
kono
parents:
diff changeset
147 end if;
kono
parents:
diff changeset
148 end Timed_Delay_T;
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 --------------------------------
kono
parents:
diff changeset
151 -- Task_Termination_Handler_T --
kono
parents:
diff changeset
152 --------------------------------
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 procedure Task_Termination_Handler_T (Excep : SSL.EO) is
kono
parents:
diff changeset
155 Self_Id : constant System.Tasking.Task_Id := STPO.Self;
kono
parents:
diff changeset
156 Cause : System.Tasking.Cause_Of_Termination;
kono
parents:
diff changeset
157 EO : Ada.Exceptions.Exception_Occurrence;
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 begin
kono
parents:
diff changeset
160 -- We can only be here because we are terminating the environment task.
kono
parents:
diff changeset
161 -- Task termination for all other tasks is handled in the Task_Wrapper.
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 -- We do not want to enable this check and e.g. call System.OS_Lib.Abort
kono
parents:
diff changeset
164 -- here because some restricted run-times may not have System.OS_Lib
kono
parents:
diff changeset
165 -- and calling abort may do more harm than good to the main application.
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 pragma Assert (Self_Id = STPO.Environment_Task);
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 -- Normal task termination
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 if Is_Null_Occurrence (Excep) then
kono
parents:
diff changeset
172 Cause := System.Tasking.Normal;
kono
parents:
diff changeset
173 Ada.Exceptions.Save_Occurrence (EO, Ada.Exceptions.Null_Occurrence);
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 -- Abnormal task termination
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 elsif Exception_Identity (Excep) = Standard'Abort_Signal'Identity then
kono
parents:
diff changeset
178 Cause := System.Tasking.Abnormal;
kono
parents:
diff changeset
179 Ada.Exceptions.Save_Occurrence (EO, Ada.Exceptions.Null_Occurrence);
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 -- Termination because of an unhandled exception
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183 else
kono
parents:
diff changeset
184 Cause := System.Tasking.Unhandled_Exception;
kono
parents:
diff changeset
185 Ada.Exceptions.Save_Occurrence (EO, Excep);
kono
parents:
diff changeset
186 end if;
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 -- There is no need for explicit protection against race conditions for
kono
parents:
diff changeset
189 -- this part because it can only be executed by the environment task
kono
parents:
diff changeset
190 -- after all the other tasks have been finalized. Note that there is no
kono
parents:
diff changeset
191 -- fall-back handler which could apply to this environment task because
kono
parents:
diff changeset
192 -- it has no parents, and, as specified in ARM C.7.3 par. 9/2, "the
kono
parents:
diff changeset
193 -- fall-back handler applies only to the dependent tasks of the task".
kono
parents:
diff changeset
194
kono
parents:
diff changeset
195 if Self_Id.Common.Specific_Handler /= null then
kono
parents:
diff changeset
196 Self_Id.Common.Specific_Handler.all (Cause, Self_Id, EO);
kono
parents:
diff changeset
197 end if;
kono
parents:
diff changeset
198 end Task_Termination_Handler_T;
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200 -----------------------------
kono
parents:
diff changeset
201 -- Init_Tasking_Soft_Links --
kono
parents:
diff changeset
202 -----------------------------
kono
parents:
diff changeset
203
kono
parents:
diff changeset
204 procedure Init_Tasking_Soft_Links is
kono
parents:
diff changeset
205 begin
kono
parents:
diff changeset
206 -- Set links only if not set already
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 if not Initialized then
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 -- Mark tasking soft links as initialized
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 Initialized := True;
kono
parents:
diff changeset
213
kono
parents:
diff changeset
214 -- The application being executed uses tasking so that the tasking
kono
parents:
diff changeset
215 -- version of the following soft links need to be used.
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 SSL.Get_Jmpbuf_Address := Get_Jmpbuf_Address'Access;
kono
parents:
diff changeset
218 SSL.Set_Jmpbuf_Address := Set_Jmpbuf_Address'Access;
kono
parents:
diff changeset
219 SSL.Get_Sec_Stack := Get_Sec_Stack'Access;
kono
parents:
diff changeset
220 SSL.Get_Stack_Info := Get_Stack_Info'Access;
kono
parents:
diff changeset
221 SSL.Set_Sec_Stack := Set_Sec_Stack'Access;
kono
parents:
diff changeset
222 SSL.Timed_Delay := Timed_Delay_T'Access;
kono
parents:
diff changeset
223 SSL.Task_Termination_Handler := Task_Termination_Handler_T'Access;
kono
parents:
diff changeset
224
kono
parents:
diff changeset
225 -- No need to create a new secondary stack, since we will use the
kono
parents:
diff changeset
226 -- default one created in s-secsta.adb.
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 SSL.Set_Sec_Stack (SSL.Get_Sec_Stack_NT);
kono
parents:
diff changeset
229 SSL.Set_Jmpbuf_Address (SSL.Get_Jmpbuf_Address_NT);
kono
parents:
diff changeset
230 end if;
kono
parents:
diff changeset
231
kono
parents:
diff changeset
232 pragma Assert (Get_Sec_Stack /= null);
kono
parents:
diff changeset
233 end Init_Tasking_Soft_Links;
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 end System.Soft_Links.Tasking;