1 ------------------------------------------------------------------------------
3 -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . T A S K I N G --
9 -- Copyright (C) 1992-2003, 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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, 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 Unchecked_Deallocation;
42 -- To recover from failure of ATCB initialization.
44 with System.Storage_Elements;
45 -- Needed for initializing Stack_Info.Size
47 with System.Parameters;
48 -- Used for Adjust_Storage_Size
50 package body System.Tasking is
52 package STPO renames System.Task_Primitives.Operations;
55 Unchecked_Deallocation (Ada_Task_Control_Block, Task_ID);
61 function Self return Task_ID renames STPO.Self;
67 procedure Initialize_ATCB
69 Task_Entry_Point : Task_Procedure_Access;
70 Task_Arg : System.Address;
72 Elaborated : Access_Boolean;
73 Base_Priority : System.Any_Priority;
74 Task_Info : System.Task_Info.Task_Info_Type;
75 Stack_Size : System.Parameters.Size_Type;
77 Success : out Boolean) is
79 T.Common.State := Unactivated;
81 -- Initialize T.Common.LL
83 STPO.Initialize_TCB (T, Success);
90 T.Common.Parent := Parent;
91 T.Common.Base_Priority := Base_Priority;
92 T.Common.Current_Priority := 0;
93 T.Common.Call := null;
94 T.Common.Task_Arg := Task_Arg;
95 T.Common.Task_Entry_Point := Task_Entry_Point;
96 T.Common.Activator := Self_ID;
97 T.Common.Wait_Count := 0;
98 T.Common.Elaborated := Elaborated;
99 T.Common.Activation_Failed := False;
100 T.Common.Task_Info := Task_Info;
102 if T.Common.Parent = null then
103 -- For the environment task, the adjusted stack size is
104 -- meaningless. For example, an unspecified Stack_Size means
105 -- that the stack size is determined by the environment, or
106 -- can grow dynamically. The Stack_Checking algorithm
107 -- therefore needs to use the requested size, or 0 in
108 -- case of an unknown size.
110 T.Common.Compiler_Data.Pri_Stack_Info.Size :=
111 Storage_Elements.Storage_Offset (Stack_Size);
114 T.Common.Compiler_Data.Pri_Stack_Info.Size :=
115 Storage_Elements.Storage_Offset
116 (Parameters.Adjust_Storage_Size (Stack_Size));
119 -- Link the task into the list of all tasks.
121 T.Common.All_Tasks_Link := All_Tasks_List;
125 Main_Task_Image : constant String := "main_task";
126 -- Image of environment task.
128 Main_Priority : Integer;
129 pragma Import (C, Main_Priority, "__gl_main_priority");
130 -- Priority for main task. Note that this is of type Integer, not
131 -- Priority, because we use the value -1 to indicate the default
132 -- main priority, and that is of course not in Priority'range.
134 ----------------------------
135 -- Tasking Initialization --
136 ----------------------------
138 -- This block constitutes the first part of the initialization of the
139 -- GNARL. This includes creating data structures to make the initial thread
140 -- into the environment task. The last part of the initialization is done
141 -- in System.Tasking.Initialization or System.Tasking.Restricted.Stages.
142 -- All the initializations used to be in Tasking.Initialization, but this
143 -- is no longer possible with the run time simplification (including
144 -- optimized PO and the restricted run time) since one cannot rely on
145 -- System.Tasking.Initialization being present, as was done before.
151 Base_Priority : Any_Priority;
154 -- Initialize Environment Task
156 if Main_Priority = Unspecified_Priority then
157 Base_Priority := Default_Priority;
159 Base_Priority := Priority (Main_Priority);
163 T := STPO.New_ATCB (0);
165 (null, null, Null_Address, Null_Task, null, Base_Priority,
166 Task_Info.Unspecified_Task_Info, 0, T, Success);
167 pragma Assert (Success);
170 STPO.Set_Priority (T, T.Common.Base_Priority);
171 T.Common.State := Runnable;
172 T.Common.Task_Image_Len := Main_Task_Image'Length;
173 T.Common.Task_Image (Main_Task_Image'Range) := Main_Task_Image;
175 -- Only initialize the first element since others are not relevant
176 -- in ravenscar mode. Rest of the initialization is done in Init_RTS.
178 T.Entry_Calls (1).Self := T;