objc/
[official-gcc.git] / gcc / ada / a-taside.adb
blobb5d92b8cb59a2e297e7c55b21172643b5f0e5810
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 pragma Warnings (Off);
35 -- Allow withing of non-Preelaborated units in Ada 2005 mode where this
36 -- package will be categorized as Preelaborate. See AI-362 for details.
37 -- It is safe in the context of the run-time to violate the rules!
39 with System.Address_Image;
40 -- used for the function itself
42 with System.Tasking;
43 -- used for Task_List
45 with System.Tasking.Stages;
46 -- used for Terminated
47 -- Abort_Tasks
49 with System.Tasking.Rendezvous;
50 -- used for Callable
52 with System.Task_Primitives.Operations;
53 -- used for Self
55 with Unchecked_Conversion;
57 pragma Warnings (Off);
59 package body Ada.Task_Identification is
61 -----------------------
62 -- Local Subprograms --
63 -----------------------
65 function Convert_Ids (T : Task_Id) return System.Tasking.Task_Id;
66 function Convert_Ids (T : System.Tasking.Task_Id) return Task_Id;
67 pragma Inline (Convert_Ids);
68 -- Conversion functions between different forms of Task_Id
70 ---------
71 -- "=" --
72 ---------
74 function "=" (Left, Right : Task_Id) return Boolean is
75 begin
76 return System.Tasking."=" (Convert_Ids (Left), Convert_Ids (Right));
77 end "=";
79 -----------------
80 -- Abort_Task --
81 ----------------
83 procedure Abort_Task (T : Task_Id) is
84 begin
85 if T = Null_Task_Id then
86 raise Program_Error;
87 else
88 System.Tasking.Stages.Abort_Tasks
89 (System.Tasking.Task_List'(1 => Convert_Ids (T)));
90 end if;
91 end Abort_Task;
93 -----------------
94 -- Convert_Ids --
95 -----------------
97 function Convert_Ids (T : Task_Id) return System.Tasking.Task_Id is
98 begin
99 return System.Tasking.Task_Id (T);
100 end Convert_Ids;
102 function Convert_Ids (T : System.Tasking.Task_Id) return Task_Id is
103 begin
104 return Task_Id (T);
105 end Convert_Ids;
107 ------------------
108 -- Current_Task --
109 ------------------
111 function Current_Task return Task_Id is
112 begin
113 return Convert_Ids (System.Task_Primitives.Operations.Self);
114 end Current_Task;
116 -----------
117 -- Image --
118 -----------
120 function Image (T : Task_Id) return String is
121 function To_Address is new
122 Unchecked_Conversion (Task_Id, System.Address);
124 begin
125 if T = Null_Task_Id then
126 return "";
128 elsif T.Common.Task_Image_Len = 0 then
129 return System.Address_Image (To_Address (T));
131 else
132 return T.Common.Task_Image (1 .. T.Common.Task_Image_Len)
133 & "_" & System.Address_Image (To_Address (T));
134 end if;
135 end Image;
137 -----------------
138 -- Is_Callable --
139 -----------------
141 function Is_Callable (T : Task_Id) return Boolean is
142 begin
143 if T = Null_Task_Id then
144 raise Program_Error;
145 else
146 return System.Tasking.Rendezvous.Callable (Convert_Ids (T));
147 end if;
148 end Is_Callable;
150 -------------------
151 -- Is_Terminated --
152 -------------------
154 function Is_Terminated (T : Task_Id) return Boolean is
155 begin
156 if T = Null_Task_Id then
157 raise Program_Error;
158 else
159 return System.Tasking.Stages.Terminated (Convert_Ids (T));
160 end if;
161 end Is_Terminated;
163 end Ada.Task_Identification;