OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-taside.adb
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 --                                                                          --
10 --           Copyright (C) 1992-2001 Free Software Foundation, Inc.         --
11 --                                                                          --
12 -- GNAT 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.  GNAT 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 GNAT;  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 -- GNAT was originally developed  by the GNAT team at  New York University. --
31 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
32 --                                                                          --
33 ------------------------------------------------------------------------------
34
35 with System.Address_Image;
36 --  used for the function itself
37
38 with System.Tasking;
39 --  used for Task_List
40
41 with System.Tasking.Stages;
42 --  used for Terminated
43 --           Abort_Tasks
44
45 with System.Tasking.Rendezvous;
46 --  used for Callable
47
48 with System.Task_Primitives.Operations;
49 --  used for Self
50
51 with System.Task_Info;
52 use type System.Task_Info.Task_Image_Type;
53
54 with Unchecked_Conversion;
55
56 package body Ada.Task_Identification is
57
58    -----------------------
59    -- Local Subprograms --
60    -----------------------
61
62    function Convert_Ids (T : Task_Id) return System.Tasking.Task_ID;
63    function Convert_Ids (T : System.Tasking.Task_ID) return Task_Id;
64    pragma Inline (Convert_Ids);
65    --  Conversion functions between different forms of Task_Id
66
67    ---------
68    -- "=" --
69    ---------
70
71    function  "=" (Left, Right : Task_Id) return Boolean is
72    begin
73       return System.Tasking."=" (Convert_Ids (Left), Convert_Ids (Right));
74    end "=";
75
76    -----------------
77    -- Abort_Task --
78    ----------------
79
80    procedure Abort_Task (T : Task_Id) is
81    begin
82       if T = Null_Task_Id then
83          raise Program_Error;
84       else
85          System.Tasking.Stages.Abort_Tasks
86            (System.Tasking.Task_List'(1 => Convert_Ids (T)));
87       end if;
88    end Abort_Task;
89
90    -----------------
91    -- Convert_Ids --
92    -----------------
93
94    function Convert_Ids (T : Task_Id) return System.Tasking.Task_ID is
95    begin
96       return System.Tasking.Task_ID (T);
97    end Convert_Ids;
98
99    function Convert_Ids (T : System.Tasking.Task_ID) return Task_Id is
100    begin
101       return Task_Id (T);
102    end Convert_Ids;
103
104    ------------------
105    -- Current_Task --
106    ------------------
107
108    function Current_Task return Task_Id is
109    begin
110       return Convert_Ids (System.Task_Primitives.Operations.Self);
111    end Current_Task;
112
113    -----------
114    -- Image --
115    -----------
116
117    function Image (T : Task_Id) return String is
118       use System.Task_Info;
119       function To_Address is new
120         Unchecked_Conversion (Task_Id, System.Address);
121
122    begin
123       if T = Null_Task_Id then
124          return "";
125
126       elsif T.Common.Task_Image = null then
127          return System.Address_Image (To_Address (T));
128
129       else
130          return T.Common.Task_Image.all
131             & "_" &  System.Address_Image (To_Address (T));
132       end if;
133    end Image;
134
135    -----------------
136    -- Is_Callable --
137    -----------------
138
139    function Is_Callable (T : Task_Id) return Boolean is
140    begin
141       if T = Null_Task_Id then
142          raise Program_Error;
143       else
144          return System.Tasking.Rendezvous.Callable (Convert_Ids (T));
145       end if;
146    end Is_Callable;
147
148    -------------------
149    -- Is_Terminated --
150    -------------------
151
152    function Is_Terminated (T : Task_Id) return Boolean is
153    begin
154       if T = Null_Task_Id then
155          raise Program_Error;
156       else
157          return System.Tasking.Stages.Terminated (Convert_Ids (T));
158       end if;
159    end Is_Terminated;
160
161 end Ada.Task_Identification;