1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . T A S K I N G --
9 -- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
11 -- GNARL 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 -- GNARL was developed by the GNARL team at Florida State University. --
28 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
30 ------------------------------------------------------------------------------
33 -- Turn off polling, we do not want ATC polling to take place during tasking
34 -- operations. It causes infinite loops and other problems.
36 with Ada
.Unchecked_Deallocation
;
38 with System
.Task_Primitives
.Operations
;
39 with System
.Storage_Elements
;
41 package body System
.Tasking
is
43 package STPO
renames System
.Task_Primitives
.Operations
;
45 ----------------------------
46 -- Free_Entry_Names_Array --
47 ----------------------------
49 procedure Free_Entry_Names_Array
(Obj
: in out Entry_Names_Array
) is
50 procedure Free_String
is new
51 Ada
.Unchecked_Deallocation
(String, String_Access
);
53 for Index
in Obj
'Range loop
54 Free_String
(Obj
(Index
));
56 end Free_Entry_Names_Array
;
62 function Detect_Blocking
return Boolean is
63 GL_Detect_Blocking
: Integer;
64 pragma Import
(C
, GL_Detect_Blocking
, "__gl_detect_blocking");
65 -- Global variable exported by the binder generated file. A value equal
66 -- to 1 indicates that pragma Detect_Blocking is active, while 0 is used
67 -- for the pragma not being present.
70 return GL_Detect_Blocking
= 1;
77 function Self
return Task_Id
renames STPO
.Self
;
83 function Storage_Size
(T
: Task_Id
) return System
.Parameters
.Size_Type
is
86 System
.Parameters
.Size_Type
87 (T
.Common
.Compiler_Data
.Pri_Stack_Info
.Size
);
94 procedure Initialize_ATCB
96 Task_Entry_Point
: Task_Procedure_Access
;
97 Task_Arg
: System
.Address
;
99 Elaborated
: Access_Boolean
;
100 Base_Priority
: System
.Any_Priority
;
101 Task_Info
: System
.Task_Info
.Task_Info_Type
;
102 Stack_Size
: System
.Parameters
.Size_Type
;
104 Success
: out Boolean)
107 T
.Common
.State
:= Unactivated
;
109 -- Initialize T.Common.LL
111 STPO
.Initialize_TCB
(T
, Success
);
117 -- Wouldn't the following be better done using an assignment of an
118 -- aggregate so that we could be sure no components were forgotten???
120 T
.Common
.Parent
:= Parent
;
121 T
.Common
.Base_Priority
:= Base_Priority
;
122 T
.Common
.Current_Priority
:= 0;
123 T
.Common
.Protected_Action_Nesting
:= 0;
124 T
.Common
.Call
:= null;
125 T
.Common
.Task_Arg
:= Task_Arg
;
126 T
.Common
.Task_Entry_Point
:= Task_Entry_Point
;
127 T
.Common
.Activator
:= Self_ID
;
128 T
.Common
.Wait_Count
:= 0;
129 T
.Common
.Elaborated
:= Elaborated
;
130 T
.Common
.Activation_Failed
:= False;
131 T
.Common
.Task_Info
:= Task_Info
;
132 T
.Common
.Global_Task_Lock_Nesting
:= 0;
133 T
.Common
.Fall_Back_Handler
:= null;
134 T
.Common
.Specific_Handler
:= null;
135 T
.Common
.Debug_Events
:= (others => False);
137 if T
.Common
.Parent
= null then
139 -- For the environment task, the adjusted stack size is meaningless.
140 -- For example, an unspecified Stack_Size means that the stack size
141 -- is determined by the environment, or can grow dynamically. The
142 -- Stack_Checking algorithm therefore needs to use the requested
143 -- size, or 0 in case of an unknown size.
145 T
.Common
.Compiler_Data
.Pri_Stack_Info
.Size
:=
146 Storage_Elements
.Storage_Offset
(Stack_Size
);
149 T
.Common
.Compiler_Data
.Pri_Stack_Info
.Size
:=
150 Storage_Elements
.Storage_Offset
151 (Parameters
.Adjust_Storage_Size
(Stack_Size
));
154 -- Link the task into the list of all tasks
156 T
.Common
.All_Tasks_Link
:= All_Tasks_List
;
164 Main_Task_Image
: constant String := "main_task";
165 -- Image of environment task
167 Main_Priority
: Integer;
168 pragma Import
(C
, Main_Priority
, "__gl_main_priority");
169 -- Priority for main task. Note that this is of type Integer, not Priority,
170 -- because we use the value -1 to indicate the default main priority, and
171 -- that is of course not in Priority'range.
173 Initialized
: Boolean := False;
174 -- Used to prevent multiple calls to Initialize
176 procedure Initialize
is
178 Base_Priority
: Any_Priority
;
188 -- Initialize Environment Task
191 (if Main_Priority
= Unspecified_Priority
192 then Default_Priority
193 else Priority
(Main_Priority
));
195 T
:= STPO
.New_ATCB
(0);
197 (null, null, Null_Address
, Null_Task
, null, Base_Priority
,
198 Task_Info
.Unspecified_Task_Info
, 0, T
, Success
);
199 pragma Assert
(Success
);
202 STPO
.Set_Priority
(T
, T
.Common
.Base_Priority
);
203 T
.Common
.State
:= Runnable
;
204 T
.Common
.Task_Image_Len
:= Main_Task_Image
'Length;
205 T
.Common
.Task_Image
(Main_Task_Image
'Range) := Main_Task_Image
;
207 -- Only initialize the first element since others are not relevant
208 -- in ravenscar mode. Rest of the initialization is done in Init_RTS.
210 T
.Entry_Calls
(1).Self
:= T
;