annotate gcc/ada/libgnarl/s-taskin.adb @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
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 RUN-TIME LIBRARY (GNARL) COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S Y S T E M . 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 -- --
kono
parents:
diff changeset
9 -- Copyright (C) 1992-2017, Free Software Foundation, Inc. --
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNARL 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 -- GNARL was developed by the GNARL team at Florida State 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 Polling (Off);
kono
parents:
diff changeset
33 -- Turn off polling, we do not want ATC polling to take place during tasking
kono
parents:
diff changeset
34 -- operations. It causes infinite loops and other problems.
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 with System.Task_Primitives.Operations;
kono
parents:
diff changeset
37 with System.Storage_Elements;
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 package body System.Tasking is
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 package STPO renames System.Task_Primitives.Operations;
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 ---------------------
kono
parents:
diff changeset
44 -- Detect_Blocking --
kono
parents:
diff changeset
45 ---------------------
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 function Detect_Blocking return Boolean is
kono
parents:
diff changeset
48 GL_Detect_Blocking : Integer;
kono
parents:
diff changeset
49 pragma Import (C, GL_Detect_Blocking, "__gl_detect_blocking");
kono
parents:
diff changeset
50 -- Global variable exported by the binder generated file. A value equal
kono
parents:
diff changeset
51 -- to 1 indicates that pragma Detect_Blocking is active, while 0 is used
kono
parents:
diff changeset
52 -- for the pragma not being present.
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 begin
kono
parents:
diff changeset
55 return GL_Detect_Blocking = 1;
kono
parents:
diff changeset
56 end Detect_Blocking;
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 -----------------------
kono
parents:
diff changeset
59 -- Number_Of_Entries --
kono
parents:
diff changeset
60 -----------------------
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 function Number_Of_Entries (Self_Id : Task_Id) return Entry_Index is
kono
parents:
diff changeset
63 begin
kono
parents:
diff changeset
64 return Entry_Index (Self_Id.Entry_Num);
kono
parents:
diff changeset
65 end Number_Of_Entries;
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 ----------
kono
parents:
diff changeset
68 -- Self --
kono
parents:
diff changeset
69 ----------
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 function Self return Task_Id renames STPO.Self;
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 ------------------
kono
parents:
diff changeset
74 -- Storage_Size --
kono
parents:
diff changeset
75 ------------------
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 function Storage_Size (T : Task_Id) return System.Parameters.Size_Type is
kono
parents:
diff changeset
78 begin
kono
parents:
diff changeset
79 return
kono
parents:
diff changeset
80 System.Parameters.Size_Type
kono
parents:
diff changeset
81 (T.Common.Compiler_Data.Pri_Stack_Info.Size);
kono
parents:
diff changeset
82 end Storage_Size;
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 ---------------------
kono
parents:
diff changeset
85 -- Initialize_ATCB --
kono
parents:
diff changeset
86 ---------------------
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 procedure Initialize_ATCB
kono
parents:
diff changeset
89 (Self_ID : Task_Id;
kono
parents:
diff changeset
90 Task_Entry_Point : Task_Procedure_Access;
kono
parents:
diff changeset
91 Task_Arg : System.Address;
kono
parents:
diff changeset
92 Parent : Task_Id;
kono
parents:
diff changeset
93 Elaborated : Access_Boolean;
kono
parents:
diff changeset
94 Base_Priority : System.Any_Priority;
kono
parents:
diff changeset
95 Base_CPU : System.Multiprocessors.CPU_Range;
kono
parents:
diff changeset
96 Domain : Dispatching_Domain_Access;
kono
parents:
diff changeset
97 Task_Info : System.Task_Info.Task_Info_Type;
kono
parents:
diff changeset
98 Stack_Size : System.Parameters.Size_Type;
kono
parents:
diff changeset
99 T : Task_Id;
kono
parents:
diff changeset
100 Success : out Boolean)
kono
parents:
diff changeset
101 is
kono
parents:
diff changeset
102 begin
kono
parents:
diff changeset
103 T.Common.State := Unactivated;
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 -- Initialize T.Common.LL
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 STPO.Initialize_TCB (T, Success);
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 if not Success then
kono
parents:
diff changeset
110 return;
kono
parents:
diff changeset
111 end if;
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 -- Note that use of an aggregate here for this assignment
kono
parents:
diff changeset
114 -- would be illegal, because Common_ATCB is limited because
kono
parents:
diff changeset
115 -- Task_Primitives.Private_Data is limited.
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 T.Common.Parent := Parent;
kono
parents:
diff changeset
118 T.Common.Base_Priority := Base_Priority;
kono
parents:
diff changeset
119 T.Common.Base_CPU := Base_CPU;
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 -- The Domain defaults to that of the activator. But that can be null in
kono
parents:
diff changeset
122 -- the case of foreign threads (see Register_Foreign_Thread), in which
kono
parents:
diff changeset
123 -- case we default to the System_Domain.
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 if Domain /= null then
kono
parents:
diff changeset
126 T.Common.Domain := Domain;
kono
parents:
diff changeset
127 elsif Self_ID.Common.Domain /= null then
kono
parents:
diff changeset
128 T.Common.Domain := Self_ID.Common.Domain;
kono
parents:
diff changeset
129 else
kono
parents:
diff changeset
130 T.Common.Domain := System_Domain;
kono
parents:
diff changeset
131 end if;
kono
parents:
diff changeset
132 pragma Assert (T.Common.Domain /= null);
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 T.Common.Current_Priority := 0;
kono
parents:
diff changeset
135 T.Common.Protected_Action_Nesting := 0;
kono
parents:
diff changeset
136 T.Common.Call := null;
kono
parents:
diff changeset
137 T.Common.Task_Arg := Task_Arg;
kono
parents:
diff changeset
138 T.Common.Task_Entry_Point := Task_Entry_Point;
kono
parents:
diff changeset
139 T.Common.Activator := Self_ID;
kono
parents:
diff changeset
140 T.Common.Wait_Count := 0;
kono
parents:
diff changeset
141 T.Common.Elaborated := Elaborated;
kono
parents:
diff changeset
142 T.Common.Activation_Failed := False;
kono
parents:
diff changeset
143 T.Common.Task_Info := Task_Info;
kono
parents:
diff changeset
144 T.Common.Global_Task_Lock_Nesting := 0;
kono
parents:
diff changeset
145 T.Common.Fall_Back_Handler := null;
kono
parents:
diff changeset
146 T.Common.Specific_Handler := null;
kono
parents:
diff changeset
147 T.Common.Debug_Events := (others => False);
kono
parents:
diff changeset
148 T.Common.Task_Image_Len := 0;
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 if T.Common.Parent = null then
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 -- For the environment task, the adjusted stack size is meaningless.
kono
parents:
diff changeset
153 -- For example, an unspecified Stack_Size means that the stack size
kono
parents:
diff changeset
154 -- is determined by the environment, or can grow dynamically. The
kono
parents:
diff changeset
155 -- Stack_Checking algorithm therefore needs to use the requested
kono
parents:
diff changeset
156 -- size, or 0 in case of an unknown size.
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 T.Common.Compiler_Data.Pri_Stack_Info.Size :=
kono
parents:
diff changeset
159 Storage_Elements.Storage_Offset (Stack_Size);
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 else
kono
parents:
diff changeset
162 T.Common.Compiler_Data.Pri_Stack_Info.Size :=
kono
parents:
diff changeset
163 Storage_Elements.Storage_Offset
kono
parents:
diff changeset
164 (Parameters.Adjust_Storage_Size (Stack_Size));
kono
parents:
diff changeset
165 end if;
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 -- Link the task into the list of all tasks
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 T.Common.All_Tasks_Link := All_Tasks_List;
kono
parents:
diff changeset
170 All_Tasks_List := T;
kono
parents:
diff changeset
171 end Initialize_ATCB;
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 ----------------
kono
parents:
diff changeset
174 -- Initialize --
kono
parents:
diff changeset
175 ----------------
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 Main_Task_Image : constant String := "main_task";
kono
parents:
diff changeset
178 -- Image of environment task
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 Main_Priority : Integer;
kono
parents:
diff changeset
181 pragma Import (C, Main_Priority, "__gl_main_priority");
kono
parents:
diff changeset
182 -- Priority for main task. Note that this is of type Integer, not Priority,
kono
parents:
diff changeset
183 -- because we use the value -1 to indicate the default main priority, and
kono
parents:
diff changeset
184 -- that is of course not in Priority'range.
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 Main_CPU : Integer;
kono
parents:
diff changeset
187 pragma Import (C, Main_CPU, "__gl_main_cpu");
kono
parents:
diff changeset
188 -- Affinity for main task. Note that this is of type Integer, not
kono
parents:
diff changeset
189 -- CPU_Range, because we use the value -1 to indicate the unassigned
kono
parents:
diff changeset
190 -- affinity, and that is of course not in CPU_Range'Range.
kono
parents:
diff changeset
191
kono
parents:
diff changeset
192 Initialized : Boolean := False;
kono
parents:
diff changeset
193 -- Used to prevent multiple calls to Initialize
kono
parents:
diff changeset
194
kono
parents:
diff changeset
195 procedure Initialize is
kono
parents:
diff changeset
196 T : Task_Id;
kono
parents:
diff changeset
197 Base_Priority : Any_Priority;
kono
parents:
diff changeset
198 Base_CPU : System.Multiprocessors.CPU_Range;
kono
parents:
diff changeset
199 Success : Boolean;
kono
parents:
diff changeset
200
kono
parents:
diff changeset
201 use type System.Multiprocessors.CPU_Range;
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 begin
kono
parents:
diff changeset
204 if Initialized then
kono
parents:
diff changeset
205 return;
kono
parents:
diff changeset
206 end if;
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 Initialized := True;
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 -- Initialize Environment Task
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 Base_Priority :=
kono
parents:
diff changeset
213 (if Main_Priority = Unspecified_Priority
kono
parents:
diff changeset
214 then Default_Priority
kono
parents:
diff changeset
215 else Priority (Main_Priority));
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 Base_CPU :=
kono
parents:
diff changeset
218 (if Main_CPU = Unspecified_CPU
kono
parents:
diff changeset
219 then System.Multiprocessors.Not_A_Specific_CPU
kono
parents:
diff changeset
220 else System.Multiprocessors.CPU_Range (Main_CPU));
kono
parents:
diff changeset
221
kono
parents:
diff changeset
222 -- At program start-up the environment task is allocated to the default
kono
parents:
diff changeset
223 -- system dispatching domain.
kono
parents:
diff changeset
224 -- Make sure that the processors which are not available are not taken
kono
parents:
diff changeset
225 -- into account. Use Number_Of_CPUs to know the exact number of
kono
parents:
diff changeset
226 -- processors in the system at execution time.
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 System_Domain :=
kono
parents:
diff changeset
229 new Dispatching_Domain'
kono
parents:
diff changeset
230 (Multiprocessors.CPU'First .. Multiprocessors.Number_Of_CPUs =>
kono
parents:
diff changeset
231 True);
kono
parents:
diff changeset
232
kono
parents:
diff changeset
233 T := STPO.New_ATCB (0);
kono
parents:
diff changeset
234 Initialize_ATCB
kono
parents:
diff changeset
235 (Self_ID => null,
kono
parents:
diff changeset
236 Task_Entry_Point => null,
kono
parents:
diff changeset
237 Task_Arg => Null_Address,
kono
parents:
diff changeset
238 Parent => Null_Task,
kono
parents:
diff changeset
239 Elaborated => null,
kono
parents:
diff changeset
240 Base_Priority => Base_Priority,
kono
parents:
diff changeset
241 Base_CPU => Base_CPU,
kono
parents:
diff changeset
242 Domain => System_Domain,
kono
parents:
diff changeset
243 Task_Info => Task_Info.Unspecified_Task_Info,
kono
parents:
diff changeset
244 Stack_Size => 0,
kono
parents:
diff changeset
245 T => T,
kono
parents:
diff changeset
246 Success => Success);
kono
parents:
diff changeset
247 pragma Assert (Success);
kono
parents:
diff changeset
248
kono
parents:
diff changeset
249 STPO.Initialize (T);
kono
parents:
diff changeset
250 STPO.Set_Priority (T, T.Common.Base_Priority);
kono
parents:
diff changeset
251 T.Common.State := Runnable;
kono
parents:
diff changeset
252 T.Common.Task_Image_Len := Main_Task_Image'Length;
kono
parents:
diff changeset
253 T.Common.Task_Image (Main_Task_Image'Range) := Main_Task_Image;
kono
parents:
diff changeset
254
kono
parents:
diff changeset
255 Dispatching_Domain_Tasks :=
kono
parents:
diff changeset
256 new Array_Allocated_Tasks'
kono
parents:
diff changeset
257 (Multiprocessors.CPU'First .. Multiprocessors.Number_Of_CPUs => 0);
kono
parents:
diff changeset
258
kono
parents:
diff changeset
259 -- Signal that this task is being allocated to a processor
kono
parents:
diff changeset
260
kono
parents:
diff changeset
261 if Base_CPU /= System.Multiprocessors.Not_A_Specific_CPU then
kono
parents:
diff changeset
262
kono
parents:
diff changeset
263 -- Increase the number of tasks attached to the CPU to which this
kono
parents:
diff changeset
264 -- task is allocated.
kono
parents:
diff changeset
265
kono
parents:
diff changeset
266 Dispatching_Domain_Tasks (Base_CPU) :=
kono
parents:
diff changeset
267 Dispatching_Domain_Tasks (Base_CPU) + 1;
kono
parents:
diff changeset
268 end if;
kono
parents:
diff changeset
269
kono
parents:
diff changeset
270 -- Only initialize the first element since others are not relevant
kono
parents:
diff changeset
271 -- in ravenscar mode. Rest of the initialization is done in Init_RTS.
kono
parents:
diff changeset
272
kono
parents:
diff changeset
273 T.Entry_Calls (1).Self := T;
kono
parents:
diff changeset
274 end Initialize;
kono
parents:
diff changeset
275 end System.Tasking;