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