Mark ChangeLog
[official-gcc.git] / gcc / ada / s-taskin.adb
blobf667a313bf32587bbc7163e8b28200f3f655a5bd
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) 1992-2004, Free Software Foundation, Inc. --
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. --
30 -- Extensive contributions were provided by Ada Core Technologies, Inc. --
31 -- --
32 ------------------------------------------------------------------------------
34 pragma Polling (Off);
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;
39 -- used for Self
41 with System.Storage_Elements;
42 -- Needed for initializing Stack_Info.Size
44 with System.Parameters;
45 -- Used for Adjust_Storage_Size
47 package body System.Tasking is
49 package STPO renames System.Task_Primitives.Operations;
51 ----------
52 -- Self --
53 ----------
55 function Self return Task_Id renames STPO.Self;
57 ---------------------
58 -- Initialize_ATCB --
59 ---------------------
61 procedure Initialize_ATCB
62 (Self_ID : Task_Id;
63 Task_Entry_Point : Task_Procedure_Access;
64 Task_Arg : System.Address;
65 Parent : Task_Id;
66 Elaborated : Access_Boolean;
67 Base_Priority : System.Any_Priority;
68 Task_Info : System.Task_Info.Task_Info_Type;
69 Stack_Size : System.Parameters.Size_Type;
70 T : Task_Id;
71 Success : out Boolean) is
72 begin
73 T.Common.State := Unactivated;
75 -- Initialize T.Common.LL
77 STPO.Initialize_TCB (T, Success);
79 if not Success then
80 return;
81 end if;
83 T.Common.Parent := Parent;
84 T.Common.Base_Priority := Base_Priority;
85 T.Common.Current_Priority := 0;
86 T.Common.Protected_Action_Nesting := 0;
87 T.Common.Call := null;
88 T.Common.Task_Arg := Task_Arg;
89 T.Common.Task_Entry_Point := Task_Entry_Point;
90 T.Common.Activator := Self_ID;
91 T.Common.Wait_Count := 0;
92 T.Common.Elaborated := Elaborated;
93 T.Common.Activation_Failed := False;
94 T.Common.Task_Info := Task_Info;
96 if T.Common.Parent = null then
97 -- For the environment task, the adjusted stack size is
98 -- meaningless. For example, an unspecified Stack_Size means
99 -- that the stack size is determined by the environment, or
100 -- can grow dynamically. The Stack_Checking algorithm
101 -- therefore needs to use the requested size, or 0 in
102 -- case of an unknown size.
104 T.Common.Compiler_Data.Pri_Stack_Info.Size :=
105 Storage_Elements.Storage_Offset (Stack_Size);
107 else
108 T.Common.Compiler_Data.Pri_Stack_Info.Size :=
109 Storage_Elements.Storage_Offset
110 (Parameters.Adjust_Storage_Size (Stack_Size));
111 end if;
113 -- Link the task into the list of all tasks.
115 T.Common.All_Tasks_Link := All_Tasks_List;
116 All_Tasks_List := T;
117 end Initialize_ATCB;
119 Main_Task_Image : constant String := "main_task";
120 -- Image of environment task.
122 Main_Priority : Integer;
123 pragma Import (C, Main_Priority, "__gl_main_priority");
124 -- Priority for main task. Note that this is of type Integer, not
125 -- Priority, because we use the value -1 to indicate the default
126 -- main priority, and that is of course not in Priority'range.
128 ----------------------------
129 -- Tasking Initialization --
130 ----------------------------
132 -- This block constitutes the first part of the initialization of the
133 -- GNARL. This includes creating data structures to make the initial thread
134 -- into the environment task. The last part of the initialization is done
135 -- in System.Tasking.Initialization or System.Tasking.Restricted.Stages.
136 -- All the initializations used to be in Tasking.Initialization, but this
137 -- is no longer possible with the run time simplification (including
138 -- optimized PO and the restricted run time) since one cannot rely on
139 -- System.Tasking.Initialization being present, as was done before.
141 begin
142 declare
143 T : Task_Id;
144 Success : Boolean;
145 Base_Priority : Any_Priority;
147 begin
148 -- Initialize Environment Task
150 if Main_Priority = Unspecified_Priority then
151 Base_Priority := Default_Priority;
152 else
153 Base_Priority := Priority (Main_Priority);
154 end if;
156 Success := True;
157 T := STPO.New_ATCB (0);
158 Initialize_ATCB
159 (null, null, Null_Address, Null_Task, null, Base_Priority,
160 Task_Info.Unspecified_Task_Info, 0, T, Success);
161 pragma Assert (Success);
163 STPO.Initialize (T);
164 STPO.Set_Priority (T, T.Common.Base_Priority);
165 T.Common.State := Runnable;
166 T.Common.Task_Image_Len := Main_Task_Image'Length;
167 T.Common.Task_Image (Main_Task_Image'Range) := Main_Task_Image;
169 -- Only initialize the first element since others are not relevant
170 -- in ravenscar mode. Rest of the initialization is done in Init_RTS.
172 T.Entry_Calls (1).Self := T;
173 end;
174 end System.Tasking;