OSDN Git Service

2003-12-11 Ed Falis <falis@gnat.com>
[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 --           Copyright (C) 1992-2002 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,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, 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 ------------------------------------------------------------------------------
33
34 with System.Address_Image;
35 --  used for the function itself
36
37 with System.Tasking;
38 --  used for Task_List
39
40 with System.Tasking.Stages;
41 --  used for Terminated
42 --           Abort_Tasks
43
44 with System.Tasking.Rendezvous;
45 --  used for Callable
46
47 with System.Task_Primitives.Operations;
48 --  used for Self
49
50 with Unchecked_Conversion;
51
52 package body Ada.Task_Identification is
53
54    -----------------------
55    -- Local Subprograms --
56    -----------------------
57
58    function Convert_Ids (T : Task_Id) return System.Tasking.Task_ID;
59    function Convert_Ids (T : System.Tasking.Task_ID) return Task_Id;
60    pragma Inline (Convert_Ids);
61    --  Conversion functions between different forms of Task_Id
62
63    ---------
64    -- "=" --
65    ---------
66
67    function  "=" (Left, Right : Task_Id) return Boolean is
68    begin
69       return System.Tasking."=" (Convert_Ids (Left), Convert_Ids (Right));
70    end "=";
71
72    -----------------
73    -- Abort_Task --
74    ----------------
75
76    procedure Abort_Task (T : Task_Id) is
77    begin
78       if T = Null_Task_Id then
79          raise Program_Error;
80       else
81          System.Tasking.Stages.Abort_Tasks
82            (System.Tasking.Task_List'(1 => Convert_Ids (T)));
83       end if;
84    end Abort_Task;
85
86    -----------------
87    -- Convert_Ids --
88    -----------------
89
90    function Convert_Ids (T : Task_Id) return System.Tasking.Task_ID is
91    begin
92       return System.Tasking.Task_ID (T);
93    end Convert_Ids;
94
95    function Convert_Ids (T : System.Tasking.Task_ID) return Task_Id is
96    begin
97       return Task_Id (T);
98    end Convert_Ids;
99
100    ------------------
101    -- Current_Task --
102    ------------------
103
104    function Current_Task return Task_Id is
105    begin
106       return Convert_Ids (System.Task_Primitives.Operations.Self);
107    end Current_Task;
108
109    -----------
110    -- Image --
111    -----------
112
113    function Image (T : Task_Id) return String is
114       function To_Address is new
115         Unchecked_Conversion (Task_Id, System.Address);
116
117    begin
118       if T = Null_Task_Id then
119          return "";
120
121       elsif T.Common.Task_Image_Len = 0 then
122          return System.Address_Image (To_Address (T));
123
124       else
125          return T.Common.Task_Image (1 .. T.Common.Task_Image_Len)
126             & "_" &  System.Address_Image (To_Address (T));
127       end if;
128    end Image;
129
130    -----------------
131    -- Is_Callable --
132    -----------------
133
134    function Is_Callable (T : Task_Id) return Boolean is
135    begin
136       if T = Null_Task_Id then
137          raise Program_Error;
138       else
139          return System.Tasking.Rendezvous.Callable (Convert_Ids (T));
140       end if;
141    end Is_Callable;
142
143    -------------------
144    -- Is_Terminated --
145    -------------------
146
147    function Is_Terminated (T : Task_Id) return Boolean is
148    begin
149       if T = Null_Task_Id then
150          raise Program_Error;
151       else
152          return System.Tasking.Stages.Terminated (Convert_Ids (T));
153       end if;
154    end Is_Terminated;
155
156 end Ada.Task_Identification;