include/ChangeLog:
[official-gcc.git] / gcc / ada / s-taskin.adb
blobba34a69f384b850ff03f3ebc7afd2694691250be
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
4 -- --
5 -- S Y S T E M . T A S K I N G --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1991-2001 Florida State University --
10 -- --
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. --
21 -- --
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. --
28 -- --
29 -- GNARL was developed by the GNARL team at Florida State University. It is --
30 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
31 -- State University (http://www.gnat.com). --
32 -- --
33 ------------------------------------------------------------------------------
35 pragma Polling (Off);
36 -- Turn off polling, we do not want ATC polling to take place during
37 -- tasking operations. It causes infinite loops and other problems.
39 with System.Task_Primitives.Operations;
40 -- used for Self
42 with Unchecked_Deallocation;
43 -- To recover from failure of ATCB initialization.
45 with System.Storage_Elements;
46 -- Needed for initializing Stack_Info.Size
48 with System.Parameters;
49 -- Used for Adjust_Storage_Size
51 package body System.Tasking is
53 package STPO renames System.Task_Primitives.Operations;
55 procedure Free is new
56 Unchecked_Deallocation (Ada_Task_Control_Block, Task_ID);
58 ----------
59 -- Self --
60 ----------
62 function Self return Task_ID renames STPO.Self;
64 ---------------------
65 -- Initialize_ATCB --
66 ---------------------
68 procedure Initialize_ATCB
69 (Self_ID : Task_ID;
70 Task_Entry_Point : Task_Procedure_Access;
71 Task_Arg : System.Address;
72 Parent : Task_ID;
73 Elaborated : Access_Boolean;
74 Base_Priority : System.Any_Priority;
75 Task_Info : System.Task_Info.Task_Info_Type;
76 Stack_Size : System.Parameters.Size_Type;
77 T : in out Task_ID;
78 Success : out Boolean) is
79 begin
80 T.Common.State := Unactivated;
82 -- Initialize T.Common.LL
84 STPO.Initialize_TCB (T, Success);
86 if not Success then
87 Free (T);
88 return;
89 end if;
91 T.Common.Parent := Parent;
92 T.Common.Base_Priority := Base_Priority;
93 T.Common.Current_Priority := 0;
94 T.Common.Call := null;
95 T.Common.Task_Arg := Task_Arg;
96 T.Common.Task_Entry_Point := Task_Entry_Point;
97 T.Common.Activator := Self_ID;
98 T.Common.Wait_Count := 0;
99 T.Common.Elaborated := Elaborated;
100 T.Common.Activation_Failed := False;
101 T.Common.Task_Info := Task_Info;
103 if T.Common.Parent = null then
104 -- For the environment task, the adjusted stack size is
105 -- meaningless. For example, an unspecified Stack_Size means
106 -- that the stack size is determined by the environment, or
107 -- can grow dynamically. The Stack_Checking algorithm
108 -- therefore needs to use the requested size, or 0 in
109 -- case of an unknown size.
111 T.Common.Compiler_Data.Pri_Stack_Info.Size :=
112 Storage_Elements.Storage_Offset (Stack_Size);
114 else
115 T.Common.Compiler_Data.Pri_Stack_Info.Size :=
116 Storage_Elements.Storage_Offset
117 (Parameters.Adjust_Storage_Size (Stack_Size));
118 end if;
120 -- Link the task into the list of all tasks.
122 T.Common.All_Tasks_Link := All_Tasks_List;
123 All_Tasks_List := T;
124 end Initialize_ATCB;
126 Main_Task_Image : aliased String := "main_task";
127 -- Declare a global variable to avoid allocating dynamic memory.
129 Main_Priority : Priority;
130 pragma Import (C, Main_Priority, "__gl_main_priority");
132 ----------------------------
133 -- Tasking Initialization --
134 ----------------------------
136 -- This block constitutes the first part of the initialization of the
137 -- GNARL. This includes creating data structures to make the initial thread
138 -- into the environment task. The last part of the initialization is done
139 -- in System.Tasking.Initialization or System.Tasking.Restricted.Stages.
140 -- All the initializations used to be in Tasking.Initialization, but this
141 -- is no longer possible with the run time simplification (including
142 -- optimized PO and the restricted run time) since one cannot rely on
143 -- System.Tasking.Initialization being present, as was done before.
145 begin
146 declare
147 T : Task_ID;
148 Success : Boolean;
149 Base_Priority : Any_Priority;
151 begin
152 -- Initialize Environment Task
154 if Main_Priority = Unspecified_Priority then
155 Base_Priority := Default_Priority;
156 else
157 Base_Priority := Main_Priority;
158 end if;
160 Success := True;
161 T := STPO.New_ATCB (0);
162 Initialize_ATCB
163 (null, null, Null_Address, Null_Task, null, Base_Priority,
164 Task_Info.Unspecified_Task_Info, 0, T, Success);
165 pragma Assert (Success);
167 STPO.Initialize (T);
168 STPO.Set_Priority (T, T.Common.Base_Priority);
169 T.Common.State := Runnable;
170 T.Common.Task_Image := Main_Task_Image'Unrestricted_Access;
172 -- Only initialize the first element since others are not relevant
173 -- in ravenscar mode. Rest of the initialization is done in Init_RTS.
175 T.Entry_Calls (1).Self := T;
176 end;
177 end System.Tasking;