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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [ada/] [s-stposu.ads] - Blame information for rev 706

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 706 jeremybenn
------------------------------------------------------------------------------
2
--                                                                          --
3
--                         GNAT COMPILER COMPONENTS                         --
4
--                                                                          --
5
--        S Y S T E M . S T O R A G E _ P O O L S . S U B P O O L S         --
6
--                                                                          --
7
--                                 S p e c                                  --
8
--                                                                          --
9
--            Copyright (C) 2011, Free Software Foundation, Inc.            --
10
--                                                                          --
11
-- This specification is derived from the Ada Reference Manual for use with --
12
-- GNAT. The copyright notice above, and the license provisions that follow --
13
-- apply solely to the  contents of the part following the private keyword. --
14
--                                                                          --
15
-- GNAT is free software;  you can  redistribute it  and/or modify it under --
16
-- terms of the  GNU General Public License as published  by the Free Soft- --
17
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
18
-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
19
-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
20
-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
21
--                                                                          --
22
-- As a special exception under Section 7 of GPL version 3, you are granted --
23
-- additional permissions described in the GCC Runtime Library Exception,   --
24
-- version 3.1, as published by the Free Software Foundation.               --
25
--                                                                          --
26
-- You should have received a copy of the GNU General Public License and    --
27
-- a copy of the GCC Runtime Library Exception along with this program;     --
28
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
29
-- <http://www.gnu.org/licenses/>.                                          --
30
--                                                                          --
31
-- GNAT was originally developed  by the GNAT team at  New York University. --
32
-- Extensive contributions were provided by Ada Core Technologies Inc.      --
33
--                                                                          --
34
------------------------------------------------------------------------------
35
 
36
with Ada.Finalization;
37
with System.Finalization_Masters;
38
with System.Storage_Elements;
39
 
40
package System.Storage_Pools.Subpools is
41
   pragma Preelaborate;
42
 
43
   type Root_Storage_Pool_With_Subpools is abstract
44
     new Root_Storage_Pool with private;
45
   --  The base for all implementations of Storage_Pool_With_Subpools. This
46
   --  type is Limited_Controlled by derivation. To use subpools, an access
47
   --  type must be associated with an implementation descending from type
48
   --  Root_Storage_Pool_With_Subpools.
49
 
50
   type Root_Subpool is abstract tagged limited private;
51
   --  The base for all implementations of Subpool. Objects of this type are
52
   --  managed by the pool_with_subpools.
53
 
54
   type Subpool_Handle is access all Root_Subpool'Class;
55
   for Subpool_Handle'Storage_Size use 0;
56
   --  Since subpools are limited types by definition, a handle is instead used
57
   --  to manage subpool abstractions.
58
 
59
   overriding procedure Allocate
60
     (Pool                     : in out Root_Storage_Pool_With_Subpools;
61
      Storage_Address          : out System.Address;
62
      Size_In_Storage_Elements : System.Storage_Elements.Storage_Count;
63
      Alignment                : System.Storage_Elements.Storage_Count);
64
   --  Allocate an object described by Size_In_Storage_Elements and Alignment
65
   --  on the default subpool of Pool. Controlled types allocated through this
66
   --  routine will NOT be handled properly.
67
 
68
   procedure Allocate_From_Subpool
69
     (Pool                     : in out Root_Storage_Pool_With_Subpools;
70
      Storage_Address          : out System.Address;
71
      Size_In_Storage_Elements : System.Storage_Elements.Storage_Count;
72
      Alignment                : System.Storage_Elements.Storage_Count;
73
      Subpool                  : not null Subpool_Handle) is abstract;
74
 
75
   --  ??? This precondition causes errors in simple tests, disabled for now
76
 
77
   --      with Pre'Class => Pool_Of_Subpool (Subpool) = Pool'Access;
78
   --  This routine requires implementation. Allocate an object described by
79
   --  Size_In_Storage_Elements and Alignment on a subpool.
80
 
81
   function Create_Subpool
82
     (Pool : in out Root_Storage_Pool_With_Subpools)
83
      return not null Subpool_Handle is abstract;
84
   --  This routine requires implementation. Create a subpool within the given
85
   --  pool_with_subpools.
86
 
87
   overriding procedure Deallocate
88
     (Pool                     : in out Root_Storage_Pool_With_Subpools;
89
      Storage_Address          : System.Address;
90
      Size_In_Storage_Elements : System.Storage_Elements.Storage_Count;
91
      Alignment                : System.Storage_Elements.Storage_Count)
92
   is null;
93
 
94
   procedure Deallocate_Subpool
95
     (Pool    : in out Root_Storage_Pool_With_Subpools;
96
      Subpool : in out Subpool_Handle)
97
   is abstract;
98
 
99
   --  ??? This precondition causes errors in simple tests, disabled for now
100
 
101
   --      with Pre'Class => Pool_Of_Subpool (Subpool) = Pool'Access;
102
   --  This routine requires implementation. Reclaim the storage a particular
103
   --  subpool occupies in a pool_with_subpools. This routine is called by
104
   --  Ada.Unchecked_Deallocate_Subpool.
105
 
106
   function Default_Subpool_For_Pool
107
     (Pool : Root_Storage_Pool_With_Subpools) return not null Subpool_Handle;
108
   --  Return a common subpool which is used for object allocations without a
109
   --  Subpool_Handle_name in the allocator. The default implementation of this
110
   --  routine raises Program_Error.
111
 
112
   function Pool_Of_Subpool
113
     (Subpool : not null Subpool_Handle)
114
      return access Root_Storage_Pool_With_Subpools'Class;
115
   --  Return the owner of the subpool
116
 
117
   procedure Set_Pool_Of_Subpool
118
     (Subpool : not null Subpool_Handle;
119
      To      : in out Root_Storage_Pool_With_Subpools'Class);
120
   --  Set the owner of the subpool. This is intended to be called from
121
   --  Create_Subpool or similar subpool constructors. Raises Program_Error
122
   --  if the subpool already belongs to a pool.
123
 
124
   overriding function Storage_Size
125
     (Pool : Root_Storage_Pool_With_Subpools)
126
      return System.Storage_Elements.Storage_Count
127
   is
128
      (System.Storage_Elements.Storage_Count'Last);
129
 
130
private
131
   --  Model
132
   --             Pool_With_Subpools     SP_Node    SP_Node    SP_Node
133
   --       +-->+--------------------+   +-----+    +-----+    +-----+
134
   --       |   |      Subpools -------->|  ------->|  ------->|  ------->
135
   --       |   +--------------------+   +-----+    +-----+    +-----+
136
   --       |   |Finalization_Started|<------  |<-------  |<-------  |<---
137
   --       |   +--------------------+   +-----+    +-----+    +-----+
138
   --       +--- Controller.Encl_Pool|   | nul |    |  +  |    |  +  |
139
   --       |   +--------------------+   +-----+    +--|--+    +--:--+
140
   --       |   :                    :    Dummy        |  ^       :
141
   --       |   :                    :                 |  |       :
142
   --       |                            Root_Subpool  V  |
143
   --       |                            +-------------+  |
144
   --       +-------------------------------- Owner    |  |
145
   --               FM_Node   FM_Node    +-------------+  |
146
   --               +-----+   +-----+<-- Master.Objects|  |
147
   --            <------  |<------  |    +-------------+  |
148
   --               +-----+   +-----+    |    Node -------+
149
   --               |  ------>|  ----->  +-------------+
150
   --               +-----+   +-----+    :             :
151
   --               |ctrl |    Dummy     :             :
152
   --               | obj |
153
   --               +-----+
154
   --
155
   --  SP_Nodes are created on the heap. FM_Nodes and associated objects are
156
   --  created on the pool_with_subpools.
157
 
158
   type Any_Storage_Pool_With_Subpools_Ptr
159
     is access all Root_Storage_Pool_With_Subpools'Class;
160
   for Any_Storage_Pool_With_Subpools_Ptr'Storage_Size use 0;
161
 
162
   --  A pool controller is a special controlled object which ensures the
163
   --  proper initialization and finalization of the enclosing pool.
164
 
165
   type Pool_Controller (Enclosing_Pool : Any_Storage_Pool_With_Subpools_Ptr)
166
     is new Ada.Finalization.Limited_Controlled with null record;
167
 
168
   --  Subpool list types. Each pool_with_subpools contains a list of subpools.
169
   --  This is an indirect doubly linked list since subpools are not supposed
170
   --  to be allocatable by language design.
171
 
172
   type SP_Node;
173
   type SP_Node_Ptr is access all SP_Node;
174
 
175
   type SP_Node is record
176
      Prev    : SP_Node_Ptr := null;
177
      Next    : SP_Node_Ptr := null;
178
      Subpool : Subpool_Handle := null;
179
   end record;
180
 
181
   --  Root_Storage_Pool_With_Subpools internal structure. The type uses a
182
   --  special controller to perform initialization and finalization actions
183
   --  on itself. This is necessary because the end user of this package may
184
   --  decide to override Initialize and Finalize, thus disabling the desired
185
   --  behavior.
186
 
187
   --          Pool_With_Subpools     SP_Node    SP_Node    SP_Node
188
   --    +-->+--------------------+   +-----+    +-----+    +-----+
189
   --    |   |      Subpools -------->|  ------->|  ------->|  ------->
190
   --    |   +--------------------+   +-----+    +-----+    +-----+
191
   --    |   |Finalization_Started|   :     :    :     :    :     :
192
   --    |   +--------------------+
193
   --    +--- Controller.Encl_Pool|
194
   --        +--------------------+
195
   --        :       End-user     :
196
   --        :      components    :
197
 
198
   type Root_Storage_Pool_With_Subpools is abstract
199
     new Root_Storage_Pool with
200
   record
201
      Subpools : aliased SP_Node;
202
      --  A doubly linked list of subpools
203
 
204
      Finalization_Started : Boolean := False;
205
      pragma Atomic (Finalization_Started);
206
      --  A flag which prevents the creation of new subpools while the master
207
      --  pool is being finalized. The flag needs to be atomic because it is
208
      --  accessed without Lock_Task / Unlock_Task.
209
 
210
      Controller : Pool_Controller
211
                     (Root_Storage_Pool_With_Subpools'Unchecked_Access);
212
      --  A component which ensures that the enclosing pool is initialized and
213
      --  finalized at the appropriate places.
214
   end record;
215
 
216
   --  A subpool is an abstraction layer which sits on top of a pool. It
217
   --  contains links to all controlled objects allocated on a particular
218
   --  subpool.
219
 
220
   --        Pool_With_Subpools   SP_Node    SP_Node    SP_Node
221
   --    +-->+----------------+   +-----+    +-----+    +-----+
222
   --    |   |    Subpools ------>|  ------->|  ------->|  ------->
223
   --    |   +----------------+   +-----+    +-----+    +-----+
224
   --    |   :                :<------  |<-------  |<-------  |
225
   --    |   :                :   +-----+    +-----+    +-----+
226
   --    |                        |null |    |  +  |    |  +  |
227
   --    |                        +-----+    +--|--+    +--:--+
228
   --    |                                      |  ^       :
229
   --    |                        Root_Subpool  V  |
230
   --    |                        +-------------+  |
231
   --    +---------------------------- Owner    |  |
232
   --                             +-------------+  |
233
   --                      .......... Master    |  |
234
   --                             +-------------+  |
235
   --                             |    Node -------+
236
   --                             +-------------+
237
   --                             :   End-user  :
238
   --                             :  components :
239
 
240
   type Root_Subpool is abstract tagged limited record
241
      Owner : Any_Storage_Pool_With_Subpools_Ptr := null;
242
      --  A reference to the master pool_with_subpools
243
 
244
      Master : aliased System.Finalization_Masters.Finalization_Master;
245
      --  A heterogeneous collection of controlled objects
246
 
247
      Node : SP_Node_Ptr := null;
248
      --  A link to the doubly linked list node which contains the subpool.
249
      --  This back pointer is used in subpool deallocation.
250
   end record;
251
 
252
   --  ??? Once Storage_Pools.Allocate_Any is removed, this should be renamed
253
   --  to Allocate_Any.
254
 
255
   procedure Allocate_Any_Controlled
256
     (Pool            : in out Root_Storage_Pool'Class;
257
      Context_Subpool : Subpool_Handle;
258
      Context_Master  : Finalization_Masters.Finalization_Master_Ptr;
259
      Fin_Address     : Finalization_Masters.Finalize_Address_Ptr;
260
      Addr            : out System.Address;
261
      Storage_Size    : System.Storage_Elements.Storage_Count;
262
      Alignment       : System.Storage_Elements.Storage_Count;
263
      Is_Controlled   : Boolean;
264
      On_Subpool      : Boolean);
265
   --  Compiler interface. This version of Allocate handles all possible cases,
266
   --  either on a pool or a pool_with_subpools, regardless of the controlled
267
   --  status of the allocated object. Parameter usage:
268
   --
269
   --    * Pool - The pool associated with the access type. Pool can be any
270
   --    derivation from Root_Storage_Pool, including a pool_with_subpools.
271
   --
272
   --    * Context_Subpool - The subpool handle name of an allocator. If no
273
   --    subpool handle is present at the point of allocation, the actual
274
   --    would be null.
275
   --
276
   --    * Context_Master - The finalization master associated with the access
277
   --    type. If the access type's designated type is not controlled, the
278
   --    actual would be null.
279
   --
280
   --    * Fin_Address - TSS routine Finalize_Address of the designated type.
281
   --    If the designated type is not controlled, the actual would be null.
282
   --
283
   --    * Addr - The address of the allocated object.
284
   --
285
   --    * Storage_Size - The size of the allocated object.
286
   --
287
   --    * Alignment - The alignment of the allocated object.
288
   --
289
   --    * Is_Controlled - A flag which determines whether the allocated object
290
   --    is controlled. When set to True, the machinery generates additional
291
   --    data.
292
   --
293
   --    * On_Subpool - A flag which determines whether the a subpool handle
294
   --    name is present at the point of allocation. This is used for error
295
   --    diagnostics.
296
 
297
   procedure Deallocate_Any_Controlled
298
     (Pool          : in out Root_Storage_Pool'Class;
299
      Addr          : System.Address;
300
      Storage_Size  : System.Storage_Elements.Storage_Count;
301
      Alignment     : System.Storage_Elements.Storage_Count;
302
      Is_Controlled : Boolean);
303
   --  Compiler interface. This version of Deallocate handles all possible
304
   --  cases, either from a pool or a pool_with_subpools, regardless of the
305
   --  controlled status of the deallocated object. Parameter usage:
306
   --
307
   --    * Pool - The pool associated with the access type. Pool can be any
308
   --    derivation from Root_Storage_Pool, including a pool_with_subpools.
309
   --
310
   --    * Addr - The address of the allocated object.
311
   --
312
   --    * Storage_Size - The size of the allocated object.
313
   --
314
   --    * Alignment - The alignment of the allocated object.
315
   --
316
   --    * Is_Controlled - A flag which determines whether the allocated object
317
   --    is controlled. When set to True, the machinery generates additional
318
   --    data.
319
 
320
   overriding procedure Finalize (Controller : in out Pool_Controller);
321
   --  Buffer routine, calls Finalize_Pool
322
 
323
   procedure Finalize_Pool (Pool : in out Root_Storage_Pool_With_Subpools);
324
   --  Iterate over all subpools of Pool, detach them one by one and finalize
325
   --  their masters. This action first detaches a controlled object from a
326
   --  particular master, then invokes its Finalize_Address primitive.
327
 
328
   procedure Finalize_Subpool (Subpool : not null Subpool_Handle);
329
   --  Finalize all controlled objects chained on Subpool's master. Remove the
330
   --  subpool from its owner's list. Deallocate the associated doubly linked
331
   --  list node.
332
 
333
   function Header_Size_With_Padding
334
     (Alignment : System.Storage_Elements.Storage_Count)
335
      return System.Storage_Elements.Storage_Count;
336
   --  Given an arbitrary alignment, calculate the size of the header which
337
   --  precedes a controlled object as the nearest multiple rounded up of the
338
   --  alignment.
339
 
340
   overriding procedure Initialize (Controller : in out Pool_Controller);
341
   --  Buffer routine, calls Initialize_Pool
342
 
343
   procedure Initialize_Pool (Pool : in out Root_Storage_Pool_With_Subpools);
344
   --  Setup the doubly linked list of subpools
345
 
346
   procedure Print_Pool (Pool : Root_Storage_Pool_With_Subpools);
347
   --  Debug routine, output the contents of a pool_with_subpools
348
 
349
   procedure Print_Subpool (Subpool : Subpool_Handle);
350
   --  Debug routine, output the contents of a subpool
351
 
352
end System.Storage_Pools.Subpools;

powered by: WebSVN 2.1.0

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