OSDN Git Service

* reload1.c (reload_cse_simplify): Fix typo in rtx code check.
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-taskin.adb
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 --                                                                          --
10 --             Copyright (C) 1991-2001 Florida State University             --
11 --                                                                          --
12 -- GNARL is free software; you can  redistribute it  and/or modify it under --
13 -- terms of the  GNU General Public License as published  by the Free Soft- --
14 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
15 -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
18 -- for  more details.  You should have  received  a copy of the GNU General --
19 -- Public License  distributed with GNARL; see file COPYING.  If not, write --
20 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
21 -- MA 02111-1307, USA.                                                      --
22 --                                                                          --
23 -- As a special exception,  if other files  instantiate  generics from this --
24 -- unit, or you link  this unit with other files  to produce an executable, --
25 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
26 -- covered  by the  GNU  General  Public  License.  This exception does not --
27 -- however invalidate  any other reasons why  the executable file  might be --
28 -- covered by the  GNU Public License.                                      --
29 --                                                                          --
30 -- GNARL was developed by the GNARL team at Florida State University. It is --
31 -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
32 -- State University (http://www.gnat.com).                                  --
33 --                                                                          --
34 ------------------------------------------------------------------------------
35
36 pragma Polling (Off);
37 --  Turn off polling, we do not want ATC polling to take place during
38 --  tasking operations. It causes infinite loops and other problems.
39
40 with System.Task_Primitives.Operations;
41 --  used for Self
42
43 with Unchecked_Deallocation;
44 --  To recover from failure of ATCB initialization.
45
46 with System.Storage_Elements;
47 --  Needed for initializing Stack_Info.Size
48
49 with System.Parameters;
50 --  Used for Adjust_Storage_Size
51
52 package body System.Tasking is
53
54    package STPO renames System.Task_Primitives.Operations;
55
56    procedure Free is new
57      Unchecked_Deallocation (Ada_Task_Control_Block, Task_ID);
58
59    ----------
60    -- Self --
61    ----------
62
63    function Self return Task_ID renames STPO.Self;
64
65    ---------------------
66    -- Initialize_ATCB --
67    ---------------------
68
69    procedure Initialize_ATCB
70      (Self_ID          : Task_ID;
71       Task_Entry_Point : Task_Procedure_Access;
72       Task_Arg         : System.Address;
73       Parent           : Task_ID;
74       Elaborated       : Access_Boolean;
75       Base_Priority    : System.Any_Priority;
76       Task_Info        : System.Task_Info.Task_Info_Type;
77       Stack_Size       : System.Parameters.Size_Type;
78       T                : in out Task_ID;
79       Success          : out Boolean) is
80    begin
81       T.Common.State := Unactivated;
82
83       --  Initialize T.Common.LL
84
85       STPO.Initialize_TCB (T, Success);
86
87       if not Success then
88          Free (T);
89          return;
90       end if;
91
92       T.Common.Parent := Parent;
93       T.Common.Base_Priority := Base_Priority;
94       T.Common.Current_Priority := 0;
95       T.Common.Call := null;
96       T.Common.Task_Arg := Task_Arg;
97       T.Common.Task_Entry_Point := Task_Entry_Point;
98       T.Common.Activator := Self_ID;
99       T.Common.Wait_Count := 0;
100       T.Common.Elaborated := Elaborated;
101       T.Common.Activation_Failed := False;
102       T.Common.Task_Info := Task_Info;
103
104       if T.Common.Parent = null then
105          --  For the environment task, the adjusted stack size is
106          --  meaningless. For example, an unspecified Stack_Size means
107          --  that the stack size is determined by the environment, or
108          --  can grow dynamically. The Stack_Checking algorithm
109          --  therefore needs to use the requested size, or 0 in
110          --  case of an unknown size.
111
112          T.Common.Compiler_Data.Pri_Stack_Info.Size :=
113             Storage_Elements.Storage_Offset (Stack_Size);
114
115       else
116          T.Common.Compiler_Data.Pri_Stack_Info.Size :=
117            Storage_Elements.Storage_Offset
118              (Parameters.Adjust_Storage_Size (Stack_Size));
119       end if;
120
121       --  Link the task into the list of all tasks.
122
123       T.Common.All_Tasks_Link := All_Tasks_List;
124       All_Tasks_List := T;
125    end Initialize_ATCB;
126
127    Main_Task_Image : aliased String := "main_task";
128    --  Declare a global variable to avoid allocating dynamic memory.
129
130    Main_Priority : Priority;
131    pragma Import (C, Main_Priority, "__gl_main_priority");
132
133    ----------------------------
134    -- Tasking Initialization --
135    ----------------------------
136
137    --  This block constitutes the first part of the initialization of the
138    --  GNARL. This includes creating data structures to make the initial thread
139    --  into the environment task. The last part of the initialization is done
140    --  in System.Tasking.Initialization or System.Tasking.Restricted.Stages.
141    --  All the initializations used to be in Tasking.Initialization, but this
142    --  is no longer possible with the run time simplification (including
143    --  optimized PO and the restricted run time) since one cannot rely on
144    --  System.Tasking.Initialization being present, as was done before.
145
146 begin
147    declare
148       T             : Task_ID;
149       Success       : Boolean;
150       Base_Priority : Any_Priority;
151
152    begin
153       --  Initialize Environment Task
154
155       if Main_Priority = Unspecified_Priority then
156          Base_Priority := Default_Priority;
157       else
158          Base_Priority := Main_Priority;
159       end if;
160
161       Success := True;
162       T := STPO.New_ATCB (0);
163       Initialize_ATCB
164         (null, null, Null_Address, Null_Task, null, Base_Priority,
165          Task_Info.Unspecified_Task_Info, 0, T, Success);
166       pragma Assert (Success);
167
168       STPO.Initialize (T);
169       STPO.Set_Priority (T, T.Common.Base_Priority);
170       T.Common.State := Runnable;
171       T.Common.Task_Image := Main_Task_Image'Unrestricted_Access;
172
173       --  Only initialize the first element since others are not relevant
174       --  in ravenscar mode. Rest of the initialization is done in Init_RTS.
175
176       T.Entry_Calls (1).Self := T;
177    end;
178 end System.Tasking;