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-2007, 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 2, or (at your option) any later ver- --
14 -- sion. GNARL 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. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNARL; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNARL was developed by the GNARL team at Florida State University. --
30 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
32 ------------------------------------------------------------------------------
35 -- Turn off polling, we do not want ATC polling to take place during
36 -- tasking operations. It causes infinite loops and other problems.
38 with System
.Task_Primitives
.Operations
;
41 with System
.Storage_Elements
;
42 -- Needed for initializing Stack_Info.Size
44 package body System
.Tasking
is
46 package STPO
renames System
.Task_Primitives
.Operations
;
52 function Detect_Blocking
return Boolean is
53 GL_Detect_Blocking
: Integer;
54 pragma Import
(C
, GL_Detect_Blocking
, "__gl_detect_blocking");
55 -- Global variable exported by the binder generated file.
56 -- A value equal to 1 indicates that pragma Detect_Blocking is active,
57 -- while 0 is used for the pragma not being present.
60 return GL_Detect_Blocking
= 1;
67 function Self
return Task_Id
renames STPO
.Self
;
73 function Storage_Size
(T
: Task_Id
) return System
.Parameters
.Size_Type
is
76 System
.Parameters
.Size_Type
77 (T
.Common
.Compiler_Data
.Pri_Stack_Info
.Size
);
84 procedure Initialize_ATCB
86 Task_Entry_Point
: Task_Procedure_Access
;
87 Task_Arg
: System
.Address
;
89 Elaborated
: Access_Boolean
;
90 Base_Priority
: System
.Any_Priority
;
91 Task_Info
: System
.Task_Info
.Task_Info_Type
;
92 Stack_Size
: System
.Parameters
.Size_Type
;
94 Success
: out Boolean) is
96 T
.Common
.State
:= Unactivated
;
98 -- Initialize T.Common.LL
100 STPO
.Initialize_TCB
(T
, Success
);
106 T
.Common
.Parent
:= Parent
;
107 T
.Common
.Base_Priority
:= Base_Priority
;
108 T
.Common
.Current_Priority
:= 0;
109 T
.Common
.Protected_Action_Nesting
:= 0;
110 T
.Common
.Call
:= null;
111 T
.Common
.Task_Arg
:= Task_Arg
;
112 T
.Common
.Task_Entry_Point
:= Task_Entry_Point
;
113 T
.Common
.Activator
:= Self_ID
;
114 T
.Common
.Wait_Count
:= 0;
115 T
.Common
.Elaborated
:= Elaborated
;
116 T
.Common
.Activation_Failed
:= False;
117 T
.Common
.Task_Info
:= Task_Info
;
118 T
.Common
.Global_Task_Lock_Nesting
:= 0;
119 T
.Common
.Fall_Back_Handler
:= null;
120 T
.Common
.Specific_Handler
:= null;
122 if T
.Common
.Parent
= null then
123 -- For the environment task, the adjusted stack size is
124 -- meaningless. For example, an unspecified Stack_Size means
125 -- that the stack size is determined by the environment, or
126 -- can grow dynamically. The Stack_Checking algorithm
127 -- therefore needs to use the requested size, or 0 in
128 -- case of an unknown size.
130 T
.Common
.Compiler_Data
.Pri_Stack_Info
.Size
:=
131 Storage_Elements
.Storage_Offset
(Stack_Size
);
134 T
.Common
.Compiler_Data
.Pri_Stack_Info
.Size
:=
135 Storage_Elements
.Storage_Offset
136 (Parameters
.Adjust_Storage_Size
(Stack_Size
));
139 -- Link the task into the list of all tasks
141 T
.Common
.All_Tasks_Link
:= All_Tasks_List
;
149 Main_Task_Image
: constant String := "main_task";
150 -- Image of environment task
152 Main_Priority
: Integer;
153 pragma Import
(C
, Main_Priority
, "__gl_main_priority");
154 -- Priority for main task. Note that this is of type Integer, not
155 -- Priority, because we use the value -1 to indicate the default
156 -- main priority, and that is of course not in Priority'range.
158 Initialized
: Boolean := False;
159 -- Used to prevent multiple calls to Initialize
161 procedure Initialize
is
163 Base_Priority
: Any_Priority
;
166 pragma Warnings
(Off
, Success
);
175 -- Initialize Environment Task
177 if Main_Priority
= Unspecified_Priority
then
178 Base_Priority
:= Default_Priority
;
180 Base_Priority
:= Priority
(Main_Priority
);
184 T
:= STPO
.New_ATCB
(0);
186 (null, null, Null_Address
, Null_Task
, null, Base_Priority
,
187 Task_Info
.Unspecified_Task_Info
, 0, T
, Success
);
188 pragma Assert
(Success
);
191 STPO
.Set_Priority
(T
, T
.Common
.Base_Priority
);
192 T
.Common
.State
:= Runnable
;
193 T
.Common
.Task_Image_Len
:= Main_Task_Image
'Length;
194 T
.Common
.Task_Image
(Main_Task_Image
'Range) := Main_Task_Image
;
196 -- Only initialize the first element since others are not relevant
197 -- in ravenscar mode. Rest of the initialization is done in Init_RTS.
199 T
.Entry_Calls
(1).Self
:= T
;