OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [ada/] [s-tataat.adb] - Blame information for rev 318

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 281 jeremybenn
------------------------------------------------------------------------------
2
--                                                                          --
3
--                 GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS                 --
4
--                                                                          --
5
--         S Y S T E M . T A S K I N G . T A S K _ A T T R I B U T E S      --
6
--                                                                          --
7
--                                  B o d y                                 --
8
--                                                                          --
9
--             Copyright (C) 1991-1994, Florida State University            --
10
--                     Copyright (C) 1995-2008, AdaCore                     --
11
--                                                                          --
12
-- GNARL 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. GNARL 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 GNARL; see file COPYING.  If not, write --
20
-- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
21
-- Boston, MA 02110-1301, 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
-- GNARL was developed by the GNARL team at Florida State University.       --
31
-- Extensive contributions were provided by Ada Core Technologies, Inc.     --
32
--                                                                          --
33
------------------------------------------------------------------------------
34
 
35
with Ada.Unchecked_Conversion;
36
 
37
with System.Task_Primitives.Operations;
38
with System.Tasking.Initialization;
39
 
40
package body System.Tasking.Task_Attributes is
41
 
42
   use Task_Primitives.Operations;
43
   use Tasking.Initialization;
44
 
45
   function To_Access_Address is new Ada.Unchecked_Conversion
46
     (Access_Node, Access_Address);
47
   --  Store pointer to indirect attribute list
48
 
49
   --------------
50
   -- Finalize --
51
   --------------
52
 
53
   procedure Finalize (X : in out Instance) is
54
      Q, To_Be_Freed : Access_Node;
55
      Self_Id        : constant Task_Id := Self;
56
 
57
   begin
58
      --  Defer abort. Note that we use the nestable versions of Defer_Abort
59
      --  and Undefer_Abort, because abort can already deferred when this is
60
      --  called during finalization, which would cause an assert failure
61
      --  in Defer_Abort.
62
 
63
      Defer_Abort_Nestable (Self_Id);
64
      Lock_RTS;
65
 
66
      --  Remove this instantiation from the list of all instantiations
67
 
68
      declare
69
         P : Access_Instance;
70
         Q : Access_Instance := All_Attributes;
71
 
72
      begin
73
         while Q /= null and then Q /= X'Unchecked_Access loop
74
            P := Q; Q := Q.Next;
75
         end loop;
76
 
77
         pragma Assert (Q /= null);
78
 
79
         if P = null then
80
            All_Attributes := Q.Next;
81
         else
82
            P.Next := Q.Next;
83
         end if;
84
      end;
85
 
86
      if X.Index /= 0 then
87
 
88
         --  Free location of this attribute, for reuse
89
 
90
         In_Use := In_Use and not (2**Natural (X.Index));
91
 
92
         --  There is no need for finalization in this case, since controlled
93
         --  types are too big to fit in the TCB.
94
 
95
      else
96
         --  Remove nodes for this attribute from the lists of all tasks,
97
         --  and deallocate the nodes. Deallocation does finalization, if
98
         --  necessary.
99
 
100
         declare
101
            C : System.Tasking.Task_Id := All_Tasks_List;
102
            P : Access_Node;
103
 
104
         begin
105
            while C /= null loop
106
               Write_Lock (C);
107
 
108
               Q := To_Access_Node (C.Indirect_Attributes);
109
               while Q /= null
110
                 and then Q.Instance /= X'Unchecked_Access
111
               loop
112
                  P := Q;
113
                  Q := Q.Next;
114
               end loop;
115
 
116
               if Q /= null then
117
                  if P = null then
118
                     C.Indirect_Attributes := To_Access_Address (Q.Next);
119
                  else
120
                     P.Next := Q.Next;
121
                  end if;
122
 
123
                  --  Can't Deallocate now since we are holding RTS_Lock
124
 
125
                  Q.Next := To_Be_Freed;
126
                  To_Be_Freed := Q;
127
               end if;
128
 
129
               Unlock (C);
130
               C := C.Common.All_Tasks_Link;
131
            end loop;
132
         end;
133
      end if;
134
 
135
      Unlock_RTS;
136
 
137
      while To_Be_Freed /= null loop
138
         Q := To_Be_Freed;
139
         To_Be_Freed := To_Be_Freed.Next;
140
         X.Deallocate.all (Q);
141
      end loop;
142
 
143
      Undefer_Abort_Nestable (Self_Id);
144
 
145
   exception
146
      when others =>
147
         null;
148
         pragma Assert (False,
149
           "Exception in task attribute instance finalization");
150
   end Finalize;
151
 
152
   -------------------------
153
   -- Finalize Attributes --
154
   -------------------------
155
 
156
   --  This is to be called just before the ATCB is deallocated.
157
   --  It relies on the caller holding T.L write-lock on entry.
158
 
159
   procedure Finalize_Attributes (T : Task_Id) is
160
      P : Access_Node;
161
      Q : Access_Node := To_Access_Node (T.Indirect_Attributes);
162
 
163
   begin
164
      --  Deallocate all the indirect attributes of this task
165
 
166
      while Q /= null loop
167
         P := Q;
168
         Q := Q.Next; P.Instance.Deallocate.all (P);
169
      end loop;
170
 
171
      T.Indirect_Attributes := null;
172
 
173
   exception
174
      when others =>
175
         null;
176
         pragma Assert (False,
177
           "Exception in per-task attributes finalization");
178
   end Finalize_Attributes;
179
 
180
   ---------------------------
181
   -- Initialize Attributes --
182
   ---------------------------
183
 
184
   --  This is to be called by System.Tasking.Stages.Create_Task
185
 
186
   procedure Initialize_Attributes (T : Task_Id) is
187
      P       : Access_Instance;
188
      Self_Id : constant Task_Id := Self;
189
 
190
   begin
191
      Defer_Abort (Self_Id);
192
      Lock_RTS;
193
 
194
      --  Initialize all the direct-access attributes of this task
195
 
196
      P := All_Attributes;
197
 
198
      while P /= null loop
199
         if P.Index /= 0 then
200
            T.Direct_Attributes (P.Index) :=
201
              Direct_Attribute_Element
202
                (System.Storage_Elements.To_Address (P.Initial_Value));
203
         end if;
204
 
205
         P := P.Next;
206
      end loop;
207
 
208
      Unlock_RTS;
209
      Undefer_Abort (Self_Id);
210
 
211
   exception
212
      when others =>
213
         null;
214
         pragma Assert (False);
215
   end Initialize_Attributes;
216
 
217
end System.Tasking.Task_Attributes;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.