* gimplify.c (find_single_pointer_decl_1): New static function.
[official-gcc.git] / gcc / ada / a-taside.adb
bloba63719d5cbe451c4fc117ce97d9bff57691aa155
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . T A S K _ I D E N T I F I C A T I O N --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2005 Free Software Foundation, Inc. --
10 -- --
11 -- GNAT 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. GNAT 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 GNAT; 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 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 -- --
32 ------------------------------------------------------------------------------
34 with System.Address_Image;
35 with System.Parameters;
36 with System.Soft_Links;
37 with System.Task_Primitives.Operations;
38 with System.Tasking;
40 with Unchecked_Conversion;
42 pragma Warnings (Off);
43 -- Allow withing of non-Preelaborated units in Ada 2005 mode where this
44 -- package will be categorized as Preelaborate. See AI-362 for details.
45 -- It is safe in the context of the run-time to violate the rules!
47 with System.Tasking.Stages;
49 pragma Warnings (On);
51 package body Ada.Task_Identification is
53 use System.Parameters;
55 package STPO renames System.Task_Primitives.Operations;
57 -----------------------
58 -- Local Subprograms --
59 -----------------------
61 function Convert_Ids (T : Task_Id) return System.Tasking.Task_Id;
62 function Convert_Ids (T : System.Tasking.Task_Id) return Task_Id;
63 pragma Inline (Convert_Ids);
64 -- Conversion functions between different forms of Task_Id
66 ---------
67 -- "=" --
68 ---------
70 function "=" (Left, Right : Task_Id) return Boolean is
71 begin
72 return System.Tasking."=" (Convert_Ids (Left), Convert_Ids (Right));
73 end "=";
75 -----------------
76 -- Abort_Task --
77 ----------------
79 procedure Abort_Task (T : Task_Id) is
80 begin
81 if T = Null_Task_Id then
82 raise Program_Error;
83 else
84 System.Tasking.Stages.Abort_Tasks
85 (System.Tasking.Task_List'(1 => Convert_Ids (T)));
86 end if;
87 end Abort_Task;
89 -----------------
90 -- Convert_Ids --
91 -----------------
93 function Convert_Ids (T : Task_Id) return System.Tasking.Task_Id is
94 begin
95 return System.Tasking.Task_Id (T);
96 end Convert_Ids;
98 function Convert_Ids (T : System.Tasking.Task_Id) return Task_Id is
99 begin
100 return Task_Id (T);
101 end Convert_Ids;
103 ------------------
104 -- Current_Task --
105 ------------------
107 function Current_Task return Task_Id is
108 begin
109 return Convert_Ids (System.Task_Primitives.Operations.Self);
110 end Current_Task;
112 -----------
113 -- Image --
114 -----------
116 function Image (T : Task_Id) return String is
117 function To_Address is new
118 Unchecked_Conversion (Task_Id, System.Address);
120 begin
121 if T = Null_Task_Id then
122 return "";
124 elsif T.Common.Task_Image_Len = 0 then
125 return System.Address_Image (To_Address (T));
127 else
128 return T.Common.Task_Image (1 .. T.Common.Task_Image_Len)
129 & "_" & System.Address_Image (To_Address (T));
130 end if;
131 end Image;
133 -----------------
134 -- Is_Callable --
135 -----------------
137 function Is_Callable (T : Task_Id) return Boolean is
138 Result : Boolean;
139 Id : constant System.Tasking.Task_Id := Convert_Ids (T);
140 begin
141 if T = Null_Task_Id then
142 raise Program_Error;
143 else
144 System.Soft_Links.Abort_Defer.all;
146 if Single_Lock then
147 STPO.Lock_RTS;
148 end if;
150 STPO.Write_Lock (Id);
151 Result := Id.Callable;
152 STPO.Unlock (Id);
154 if Single_Lock then
155 STPO.Unlock_RTS;
156 end if;
158 System.Soft_Links.Abort_Undefer.all;
159 return Result;
160 end if;
161 end Is_Callable;
163 -------------------
164 -- Is_Terminated --
165 -------------------
167 function Is_Terminated (T : Task_Id) return Boolean is
168 Result : Boolean;
169 Id : constant System.Tasking.Task_Id := Convert_Ids (T);
171 use System.Tasking;
173 begin
174 if T = Null_Task_Id then
175 raise Program_Error;
176 else
177 System.Soft_Links.Abort_Defer.all;
179 if Single_Lock then
180 STPO.Lock_RTS;
181 end if;
183 STPO.Write_Lock (Id);
184 Result := Id.Common.State = Terminated;
185 STPO.Unlock (Id);
187 if Single_Lock then
188 STPO.Unlock_RTS;
189 end if;
191 System.Soft_Links.Abort_Undefer.all;
192 return Result;
193 end if;
194 end Is_Terminated;
196 end Ada.Task_Identification;