1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- S Y S T E M . P O O L _ L O C A L --
10 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
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. --
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. --
30 -- GNAT was originally developed by the GNAT team at New York University. --
31 -- Extensive contributions were provided by Ada Core Technologies Inc. --
33 ------------------------------------------------------------------------------
36 with System
.Storage_Elements
;
37 with System
.Address_To_Access_Conversions
;
39 package body System
.Pool_Local
is
41 package SSE
renames System
.Storage_Elements
;
42 use type SSE
.Storage_Offset
;
44 Pointer_Size
: constant SSE
.Storage_Offset
:= Address
'Size / Storage_Unit
;
45 Pointers_Size
: constant SSE
.Storage_Offset
:= 2 * Pointer_Size
;
47 type Acc_Address
is access all Address
;
48 package Addr
is new Address_To_Access_Conversions
(Address
);
50 -----------------------
51 -- Local Subprograms --
52 -----------------------
54 function Next
(A
: Address
) return Acc_Address
;
55 -- Given an address of a block, return an access to the next block
57 function Prev
(A
: Address
) return Acc_Address
;
58 -- Given an address of a block, return an access to the previous block
65 (Pool
: in out Unbounded_Reclaim_Pool
;
66 Address
: out System
.Address
;
67 Storage_Size
: SSE
.Storage_Count
;
68 Alignment
: SSE
.Storage_Count
)
70 pragma Warnings
(Off
, Alignment
);
72 Allocated
: constant System
.Address
:=
74 (Memory
.size_t
(Storage_Size
+ Pointers_Size
));
77 -- The call to Alloc returns an address whose alignment is compatible
78 -- with the worst case alignment requirement for the machine; thus the
79 -- Alignment argument can be safely ignored.
81 if Allocated
= Null_Address
then
84 Address
:= Allocated
+ Pointers_Size
;
85 Next
(Allocated
).all := Pool
.First
;
86 Prev
(Allocated
).all := Null_Address
;
88 if Pool
.First
/= Null_Address
then
89 Prev
(Pool
.First
).all := Allocated
;
92 Pool
.First
:= Allocated
;
101 (Pool
: in out Unbounded_Reclaim_Pool
;
102 Address
: System
.Address
;
103 Storage_Size
: SSE
.Storage_Count
;
104 Alignment
: SSE
.Storage_Count
)
106 pragma Warnings
(Off
, Storage_Size
);
107 pragma Warnings
(Off
, Alignment
);
109 Allocated
: constant System
.Address
:= Address
- Pointers_Size
;
112 if Prev
(Allocated
).all = Null_Address
then
113 Pool
.First
:= Next
(Allocated
).all;
114 Prev
(Pool
.First
).all := Null_Address
;
116 Next
(Prev
(Allocated
).all).all := Next
(Allocated
).all;
119 if Next
(Allocated
).all /= Null_Address
then
120 Prev
(Next
(Allocated
).all).all := Prev
(Allocated
).all;
123 Memory
.Free
(Allocated
);
130 procedure Finalize
(Pool
: in out Unbounded_Reclaim_Pool
) is
131 N
: System
.Address
:= Pool
.First
;
132 Allocated
: System
.Address
;
135 while N
/= Null_Address
loop
138 Memory
.Free
(Allocated
);
146 function Next
(A
: Address
) return Acc_Address
is
148 return Acc_Address
(Addr
.To_Pointer
(A
));
155 function Prev
(A
: Address
) return Acc_Address
is
157 return Acc_Address
(Addr
.To_Pointer
(A
+ Pointer_Size
));
160 end System
.Pool_Local
;