1 ------------------------------------------------------------------------------
3 -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . T A S K I N G --
10 -- Copyright (C) 1991-2001 Florida State University --
12 -- GNARL is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNARL; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- As a special exception, if other files instantiate generics from this --
24 -- unit, or you link this unit with other files to produce an executable, --
25 -- this unit does not by itself cause the resulting executable to be --
26 -- covered by the GNU General Public License. This exception does not --
27 -- however invalidate any other reasons why the executable file might be --
28 -- covered by the GNU Public License. --
30 -- GNARL was developed by the GNARL team at Florida State University. It is --
31 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
32 -- State University (http://www.gnat.com). --
34 ------------------------------------------------------------------------------
37 -- Turn off polling, we do not want ATC polling to take place during
38 -- tasking operations. It causes infinite loops and other problems.
40 with System
.Task_Primitives
.Operations
;
43 with Unchecked_Deallocation
;
44 -- To recover from failure of ATCB initialization.
46 with System
.Storage_Elements
;
47 -- Needed for initializing Stack_Info.Size
49 with System
.Parameters
;
50 -- Used for Adjust_Storage_Size
52 package body System
.Tasking
is
54 package STPO
renames System
.Task_Primitives
.Operations
;
57 Unchecked_Deallocation
(Ada_Task_Control_Block
, Task_ID
);
63 function Self
return Task_ID
renames STPO
.Self
;
69 procedure Initialize_ATCB
71 Task_Entry_Point
: Task_Procedure_Access
;
72 Task_Arg
: System
.Address
;
74 Elaborated
: Access_Boolean
;
75 Base_Priority
: System
.Any_Priority
;
76 Task_Info
: System
.Task_Info
.Task_Info_Type
;
77 Stack_Size
: System
.Parameters
.Size_Type
;
79 Success
: out Boolean) is
81 T
.Common
.State
:= Unactivated
;
83 -- Initialize T.Common.LL
85 STPO
.Initialize_TCB
(T
, Success
);
92 T
.Common
.Parent
:= Parent
;
93 T
.Common
.Base_Priority
:= Base_Priority
;
94 T
.Common
.Current_Priority
:= 0;
95 T
.Common
.Call
:= null;
96 T
.Common
.Task_Arg
:= Task_Arg
;
97 T
.Common
.Task_Entry_Point
:= Task_Entry_Point
;
98 T
.Common
.Activator
:= Self_ID
;
99 T
.Common
.Wait_Count
:= 0;
100 T
.Common
.Elaborated
:= Elaborated
;
101 T
.Common
.Activation_Failed
:= False;
102 T
.Common
.Task_Info
:= Task_Info
;
104 if T
.Common
.Parent
= null then
105 -- For the environment task, the adjusted stack size is
106 -- meaningless. For example, an unspecified Stack_Size means
107 -- that the stack size is determined by the environment, or
108 -- can grow dynamically. The Stack_Checking algorithm
109 -- therefore needs to use the requested size, or 0 in
110 -- case of an unknown size.
112 T
.Common
.Compiler_Data
.Pri_Stack_Info
.Size
:=
113 Storage_Elements
.Storage_Offset
(Stack_Size
);
116 T
.Common
.Compiler_Data
.Pri_Stack_Info
.Size
:=
117 Storage_Elements
.Storage_Offset
118 (Parameters
.Adjust_Storage_Size
(Stack_Size
));
121 -- Link the task into the list of all tasks.
123 T
.Common
.All_Tasks_Link
:= All_Tasks_List
;
127 Main_Task_Image
: aliased String := "main_task";
128 -- Declare a global variable to avoid allocating dynamic memory.
130 Main_Priority
: Priority
;
131 pragma Import
(C
, Main_Priority
, "__gl_main_priority");
133 ----------------------------
134 -- Tasking Initialization --
135 ----------------------------
137 -- This block constitutes the first part of the initialization of the
138 -- GNARL. This includes creating data structures to make the initial thread
139 -- into the environment task. The last part of the initialization is done
140 -- in System.Tasking.Initialization or System.Tasking.Restricted.Stages.
141 -- All the initializations used to be in Tasking.Initialization, but this
142 -- is no longer possible with the run time simplification (including
143 -- optimized PO and the restricted run time) since one cannot rely on
144 -- System.Tasking.Initialization being present, as was done before.
150 Base_Priority
: Any_Priority
;
153 -- Initialize Environment Task
155 if Main_Priority
= Unspecified_Priority
then
156 Base_Priority
:= Default_Priority
;
158 Base_Priority
:= Main_Priority
;
162 T
:= STPO
.New_ATCB
(0);
164 (null, null, Null_Address
, Null_Task
, null, Base_Priority
,
165 Task_Info
.Unspecified_Task_Info
, 0, T
, Success
);
166 pragma Assert
(Success
);
169 STPO
.Set_Priority
(T
, T
.Common
.Base_Priority
);
170 T
.Common
.State
:= Runnable
;
171 T
.Common
.Task_Image
:= Main_Task_Image
'Unrestricted_Access;
173 -- Only initialize the first element since others are not relevant
174 -- in ravenscar mode. Rest of the initialization is done in Init_RTS.
176 T
.Entry_Calls
(1).Self
:= T
;