Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / gcc / ada / s-taskin.adb
blob6c0ef7a04e697071a7b63b7ea82d3e589690d63d
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT 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-2005, 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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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 -- Detect_Blocking --
53 ---------------------
55 function Detect_Blocking return Boolean is
56 GL_Detect_Blocking : Integer;
57 pragma Import (C, GL_Detect_Blocking, "__gl_detect_blocking");
58 -- Global variable exported by the binder generated file.
59 -- A value equal to 1 indicates that pragma Detect_Blocking is active,
60 -- while 0 is used for the pragma not being present.
62 begin
63 return GL_Detect_Blocking = 1;
64 end Detect_Blocking;
66 ----------
67 -- Self --
68 ----------
70 function Self return Task_Id renames STPO.Self;
72 ---------------------
73 -- Initialize_ATCB --
74 ---------------------
76 procedure Initialize_ATCB
77 (Self_ID : Task_Id;
78 Task_Entry_Point : Task_Procedure_Access;
79 Task_Arg : System.Address;
80 Parent : Task_Id;
81 Elaborated : Access_Boolean;
82 Base_Priority : System.Any_Priority;
83 Task_Info : System.Task_Info.Task_Info_Type;
84 Stack_Size : System.Parameters.Size_Type;
85 T : Task_Id;
86 Success : out Boolean) is
87 begin
88 T.Common.State := Unactivated;
90 -- Initialize T.Common.LL
92 STPO.Initialize_TCB (T, Success);
94 if not Success then
95 return;
96 end if;
98 T.Common.Parent := Parent;
99 T.Common.Base_Priority := Base_Priority;
100 T.Common.Current_Priority := 0;
101 T.Common.Protected_Action_Nesting := 0;
102 T.Common.Call := null;
103 T.Common.Task_Arg := Task_Arg;
104 T.Common.Task_Entry_Point := Task_Entry_Point;
105 T.Common.Activator := Self_ID;
106 T.Common.Wait_Count := 0;
107 T.Common.Elaborated := Elaborated;
108 T.Common.Activation_Failed := False;
109 T.Common.Task_Info := Task_Info;
110 T.Common.Global_Task_Lock_Nesting := 0;
111 T.Common.Fall_Back_Handler := null;
112 T.Common.Specific_Handler := null;
114 if T.Common.Parent = null then
115 -- For the environment task, the adjusted stack size is
116 -- meaningless. For example, an unspecified Stack_Size means
117 -- that the stack size is determined by the environment, or
118 -- can grow dynamically. The Stack_Checking algorithm
119 -- therefore needs to use the requested size, or 0 in
120 -- case of an unknown size.
122 T.Common.Compiler_Data.Pri_Stack_Info.Size :=
123 Storage_Elements.Storage_Offset (Stack_Size);
125 else
126 T.Common.Compiler_Data.Pri_Stack_Info.Size :=
127 Storage_Elements.Storage_Offset
128 (Parameters.Adjust_Storage_Size (Stack_Size));
129 end if;
131 -- Link the task into the list of all tasks.
133 T.Common.All_Tasks_Link := All_Tasks_List;
134 All_Tasks_List := T;
135 end Initialize_ATCB;
137 ----------------
138 -- Initialize --
139 ----------------
141 Main_Task_Image : constant String := "main_task";
142 -- Image of environment task
144 Main_Priority : Integer;
145 pragma Import (C, Main_Priority, "__gl_main_priority");
146 -- Priority for main task. Note that this is of type Integer, not
147 -- Priority, because we use the value -1 to indicate the default
148 -- main priority, and that is of course not in Priority'range.
150 Initialized : Boolean := False;
151 -- Used to prevent multiple calls to Initialize
153 procedure Initialize is
154 T : Task_Id;
155 Success : Boolean;
156 Base_Priority : Any_Priority;
158 begin
159 if Initialized then
160 return;
161 end if;
163 Initialized := True;
165 -- Initialize Environment Task
167 if Main_Priority = Unspecified_Priority then
168 Base_Priority := Default_Priority;
169 else
170 Base_Priority := Priority (Main_Priority);
171 end if;
173 Success := True;
174 T := STPO.New_ATCB (0);
175 Initialize_ATCB
176 (null, null, Null_Address, Null_Task, null, Base_Priority,
177 Task_Info.Unspecified_Task_Info, 0, T, Success);
178 pragma Assert (Success);
180 STPO.Initialize (T);
181 STPO.Set_Priority (T, T.Common.Base_Priority);
182 T.Common.State := Runnable;
183 T.Common.Task_Image_Len := Main_Task_Image'Length;
184 T.Common.Task_Image (Main_Task_Image'Range) := Main_Task_Image;
186 -- Only initialize the first element since others are not relevant
187 -- in ravenscar mode. Rest of the initialization is done in Init_RTS.
189 T.Entry_Calls (1).Self := T;
190 end Initialize;
192 end System.Tasking;