2016-04-18 Ed Schonberg <schonberg@adacore.com>
[official-gcc.git] / gcc / ada / a-taside.adb
blobb916c7609a141cdacab4aed38e8db388b7af11b1
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-2013, 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 3, 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. --
17 -- --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
21 -- --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
32 with System.Address_Image;
33 with System.Parameters;
34 with System.Soft_Links;
35 with System.Task_Primitives;
36 with System.Task_Primitives.Operations;
37 with Ada.Unchecked_Conversion;
39 pragma Warnings (Off);
40 -- Allow withing of non-Preelaborated units in Ada 2005 mode where this
41 -- package will be categorized as Preelaborate. See AI-362 for details.
42 -- It is safe in the context of the run-time to violate the rules.
44 with System.Tasking.Utilities;
46 pragma Warnings (On);
48 package body Ada.Task_Identification with
49 SPARK_Mode => Off
52 use System.Parameters;
54 package STPO renames System.Task_Primitives.Operations;
56 -----------------------
57 -- Local Subprograms --
58 -----------------------
60 function Convert_Ids (T : Task_Id) return System.Tasking.Task_Id;
61 function Convert_Ids (T : System.Tasking.Task_Id) return Task_Id;
62 pragma Inline (Convert_Ids);
63 -- Conversion functions between different forms of Task_Id
65 ---------
66 -- "=" --
67 ---------
69 function "=" (Left, Right : Task_Id) return Boolean is
70 begin
71 return System.Tasking."=" (Convert_Ids (Left), Convert_Ids (Right));
72 end "=";
74 -----------------
75 -- Abort_Task --
76 ----------------
78 procedure Abort_Task (T : Task_Id) is
79 begin
80 if T = Null_Task_Id then
81 raise Program_Error;
82 else
83 System.Tasking.Utilities.Abort_Tasks
84 (System.Tasking.Task_List'(1 => Convert_Ids (T)));
85 end if;
86 end Abort_Task;
88 ----------------------------
89 -- Activation_Is_Complete --
90 ----------------------------
92 function Activation_Is_Complete (T : Task_Id) return Boolean is
93 use type System.Tasking.Task_Id;
94 begin
95 return Convert_Ids (T).Common.Activator = null;
96 end Activation_Is_Complete;
98 -----------------
99 -- Convert_Ids --
100 -----------------
102 function Convert_Ids (T : Task_Id) return System.Tasking.Task_Id is
103 begin
104 return System.Tasking.Task_Id (T);
105 end Convert_Ids;
107 function Convert_Ids (T : System.Tasking.Task_Id) return Task_Id is
108 begin
109 return Task_Id (T);
110 end Convert_Ids;
112 ------------------
113 -- Current_Task --
114 ------------------
116 function Current_Task return Task_Id is
117 begin
118 return Convert_Ids (System.Task_Primitives.Operations.Self);
119 end Current_Task;
121 ----------------------
122 -- Environment_Task --
123 ----------------------
125 function Environment_Task return Task_Id is
126 begin
127 return Convert_Ids (System.Task_Primitives.Operations.Environment_Task);
128 end Environment_Task;
130 -----------
131 -- Image --
132 -----------
134 function Image (T : Task_Id) return String is
135 function To_Address is new
136 Ada.Unchecked_Conversion
137 (Task_Id, System.Task_Primitives.Task_Address);
139 begin
140 if T = Null_Task_Id then
141 return "";
143 elsif T.Common.Task_Image_Len = 0 then
144 return System.Address_Image (To_Address (T));
146 else
147 return T.Common.Task_Image (1 .. T.Common.Task_Image_Len)
148 & "_" & System.Address_Image (To_Address (T));
149 end if;
150 end Image;
152 -----------------
153 -- Is_Callable --
154 -----------------
156 function Is_Callable (T : Task_Id) return Boolean is
157 Result : Boolean;
158 Id : constant System.Tasking.Task_Id := Convert_Ids (T);
159 begin
160 if T = Null_Task_Id then
161 raise Program_Error;
162 else
163 System.Soft_Links.Abort_Defer.all;
165 if Single_Lock then
166 STPO.Lock_RTS;
167 end if;
169 STPO.Write_Lock (Id);
170 Result := Id.Callable;
171 STPO.Unlock (Id);
173 if Single_Lock then
174 STPO.Unlock_RTS;
175 end if;
177 System.Soft_Links.Abort_Undefer.all;
178 return Result;
179 end if;
180 end Is_Callable;
182 -------------------
183 -- Is_Terminated --
184 -------------------
186 function Is_Terminated (T : Task_Id) return Boolean is
187 Result : Boolean;
188 Id : constant System.Tasking.Task_Id := Convert_Ids (T);
190 use System.Tasking;
192 begin
193 if T = Null_Task_Id then
194 raise Program_Error;
195 else
196 System.Soft_Links.Abort_Defer.all;
198 if Single_Lock then
199 STPO.Lock_RTS;
200 end if;
202 STPO.Write_Lock (Id);
203 Result := Id.Common.State = Terminated;
204 STPO.Unlock (Id);
206 if Single_Lock then
207 STPO.Unlock_RTS;
208 end if;
210 System.Soft_Links.Abort_Undefer.all;
211 return Result;
212 end if;
213 end Is_Terminated;
215 end Ada.Task_Identification;