1 | /* heap.inl |
---|
2 | * |
---|
3 | * This file contains the static inline implementation of the inlined |
---|
4 | * routines from the heap handler. |
---|
5 | * |
---|
6 | * COPYRIGHT (c) 1989-1997. |
---|
7 | * On-Line Applications Research Corporation (OAR). |
---|
8 | * Copyright assigned to U.S. Government, 1994. |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.OARcorp.com/rtems/license.html. |
---|
13 | * |
---|
14 | * $Id$ |
---|
15 | */ |
---|
16 | |
---|
17 | #ifndef __HEAP_inl |
---|
18 | #define __HEAP_inl |
---|
19 | |
---|
20 | #include <rtems/score/address.h> |
---|
21 | |
---|
22 | /*PAGE |
---|
23 | * |
---|
24 | * _Heap_Head |
---|
25 | * |
---|
26 | * DESCRIPTION: |
---|
27 | * |
---|
28 | * This function returns the head of the specified heap. |
---|
29 | */ |
---|
30 | |
---|
31 | RTEMS_INLINE_ROUTINE Heap_Block *_Heap_Head ( |
---|
32 | Heap_Control *the_heap |
---|
33 | ) |
---|
34 | { |
---|
35 | return (Heap_Block *)&the_heap->start; |
---|
36 | } |
---|
37 | |
---|
38 | /*PAGE |
---|
39 | * |
---|
40 | * _Heap_Tail |
---|
41 | * |
---|
42 | * DESCRIPTION: |
---|
43 | * |
---|
44 | * This function returns the tail of the specified heap. |
---|
45 | */ |
---|
46 | |
---|
47 | RTEMS_INLINE_ROUTINE Heap_Block *_Heap_Tail ( |
---|
48 | Heap_Control *the_heap |
---|
49 | ) |
---|
50 | { |
---|
51 | return (Heap_Block *)&the_heap->final; |
---|
52 | } |
---|
53 | |
---|
54 | /*PAGE |
---|
55 | * |
---|
56 | * _Heap_Previous_block |
---|
57 | * |
---|
58 | * DESCRIPTION: |
---|
59 | * |
---|
60 | * This function returns the address of the block which physically |
---|
61 | * precedes the_block in memory. |
---|
62 | */ |
---|
63 | |
---|
64 | RTEMS_INLINE_ROUTINE Heap_Block *_Heap_Previous_block ( |
---|
65 | Heap_Block *the_block |
---|
66 | ) |
---|
67 | { |
---|
68 | return (Heap_Block *) _Addresses_Subtract_offset( |
---|
69 | (void *)the_block, |
---|
70 | the_block->back_flag & ~ HEAP_BLOCK_USED |
---|
71 | ); |
---|
72 | } |
---|
73 | |
---|
74 | /*PAGE |
---|
75 | * |
---|
76 | * _Heap_Next_block |
---|
77 | * |
---|
78 | * DESCRIPTION: |
---|
79 | * |
---|
80 | * This function returns the address of the block which physically |
---|
81 | * follows the_block in memory. |
---|
82 | * |
---|
83 | * NOTE: Next_block assumes that the block is free. |
---|
84 | */ |
---|
85 | |
---|
86 | RTEMS_INLINE_ROUTINE Heap_Block *_Heap_Next_block ( |
---|
87 | Heap_Block *the_block |
---|
88 | ) |
---|
89 | { |
---|
90 | return (Heap_Block *) _Addresses_Add_offset( |
---|
91 | (void *)the_block, |
---|
92 | the_block->front_flag & ~ HEAP_BLOCK_USED |
---|
93 | ); |
---|
94 | } |
---|
95 | |
---|
96 | /*PAGE |
---|
97 | * |
---|
98 | * _Heap_Block_at |
---|
99 | * |
---|
100 | * DESCRIPTION: |
---|
101 | * |
---|
102 | * This function calculates and returns a block's location (address) |
---|
103 | * in the heap based upad a base address and an offset. |
---|
104 | */ |
---|
105 | |
---|
106 | RTEMS_INLINE_ROUTINE Heap_Block *_Heap_Block_at( |
---|
107 | void *base, |
---|
108 | unsigned32 offset |
---|
109 | ) |
---|
110 | { |
---|
111 | return (Heap_Block *) _Addresses_Add_offset( (void *)base, offset ); |
---|
112 | } |
---|
113 | |
---|
114 | /*PAGE |
---|
115 | * |
---|
116 | * _Heap_User_block_at |
---|
117 | * |
---|
118 | * DESCRIPTION: |
---|
119 | * |
---|
120 | * XXX |
---|
121 | */ |
---|
122 | |
---|
123 | RTEMS_INLINE_ROUTINE Heap_Block *_Heap_User_block_at( |
---|
124 | void *base |
---|
125 | ) |
---|
126 | { |
---|
127 | unsigned32 offset; |
---|
128 | |
---|
129 | offset = *(((unsigned32 *) base) - 1); |
---|
130 | return _Heap_Block_at( base, -offset + -HEAP_BLOCK_USED_OVERHEAD); |
---|
131 | } |
---|
132 | |
---|
133 | /*PAGE |
---|
134 | * |
---|
135 | * _Heap_Is_previous_block_free |
---|
136 | * |
---|
137 | * DESCRIPTION: |
---|
138 | * |
---|
139 | * This function returns TRUE if the previous block of the_block |
---|
140 | * is free, and FALSE otherwise. |
---|
141 | */ |
---|
142 | |
---|
143 | RTEMS_INLINE_ROUTINE boolean _Heap_Is_previous_block_free ( |
---|
144 | Heap_Block *the_block |
---|
145 | ) |
---|
146 | { |
---|
147 | return !(the_block->back_flag & HEAP_BLOCK_USED); |
---|
148 | } |
---|
149 | |
---|
150 | /*PAGE |
---|
151 | * |
---|
152 | * _Heap_Is_block_free |
---|
153 | * |
---|
154 | * DESCRIPTION: |
---|
155 | * |
---|
156 | * This function returns TRUE if the block is free, and FALSE otherwise. |
---|
157 | */ |
---|
158 | |
---|
159 | RTEMS_INLINE_ROUTINE boolean _Heap_Is_block_free ( |
---|
160 | Heap_Block *the_block |
---|
161 | ) |
---|
162 | { |
---|
163 | return !(the_block->front_flag & HEAP_BLOCK_USED); |
---|
164 | } |
---|
165 | |
---|
166 | /*PAGE |
---|
167 | * |
---|
168 | * _Heap_Is_block_used |
---|
169 | * |
---|
170 | * DESCRIPTION: |
---|
171 | * |
---|
172 | * This function returns TRUE if the block is currently allocated, |
---|
173 | * and FALSE otherwise. |
---|
174 | */ |
---|
175 | |
---|
176 | RTEMS_INLINE_ROUTINE boolean _Heap_Is_block_used ( |
---|
177 | Heap_Block *the_block |
---|
178 | ) |
---|
179 | { |
---|
180 | return (the_block->front_flag & HEAP_BLOCK_USED); |
---|
181 | } |
---|
182 | |
---|
183 | /*PAGE |
---|
184 | * |
---|
185 | * _Heap_Block_size |
---|
186 | * |
---|
187 | * DESCRIPTION: |
---|
188 | * |
---|
189 | * This function returns the size of the_block in bytes. |
---|
190 | */ |
---|
191 | |
---|
192 | RTEMS_INLINE_ROUTINE unsigned32 _Heap_Block_size ( |
---|
193 | Heap_Block *the_block |
---|
194 | ) |
---|
195 | { |
---|
196 | return (the_block->front_flag & ~HEAP_BLOCK_USED); |
---|
197 | } |
---|
198 | |
---|
199 | /*PAGE |
---|
200 | * |
---|
201 | * _Heap_Start_of_user_area |
---|
202 | * |
---|
203 | * DESCRIPTION: |
---|
204 | * |
---|
205 | * This function returns the starting address of the portion of the block |
---|
206 | * which the user may access. |
---|
207 | */ |
---|
208 | |
---|
209 | RTEMS_INLINE_ROUTINE void *_Heap_Start_of_user_area ( |
---|
210 | Heap_Block *the_block |
---|
211 | ) |
---|
212 | { |
---|
213 | return (void *) &the_block->next; |
---|
214 | } |
---|
215 | |
---|
216 | /*PAGE |
---|
217 | * |
---|
218 | * _Heap_Is_block_in |
---|
219 | * |
---|
220 | * DESCRIPTION: |
---|
221 | * |
---|
222 | * This function returns TRUE if the_block is within the memory area |
---|
223 | * managed by the_heap, and FALSE otherwise. |
---|
224 | */ |
---|
225 | |
---|
226 | RTEMS_INLINE_ROUTINE boolean _Heap_Is_block_in ( |
---|
227 | Heap_Control *the_heap, |
---|
228 | Heap_Block *the_block |
---|
229 | ) |
---|
230 | { |
---|
231 | return _Addresses_Is_in_range( the_block, the_heap->start, the_heap->final ); |
---|
232 | } |
---|
233 | |
---|
234 | /*PAGE |
---|
235 | * |
---|
236 | * _Heap_Is_page_size_valid |
---|
237 | * |
---|
238 | * DESCRIPTION: |
---|
239 | * |
---|
240 | * This function validates a specified heap page size. If the page size |
---|
241 | * is 0 or if lies outside a page size alignment boundary it is invalid |
---|
242 | * and FALSE is returned. Otherwise, the page size is valid and TRUE is |
---|
243 | * returned. |
---|
244 | */ |
---|
245 | |
---|
246 | RTEMS_INLINE_ROUTINE boolean _Heap_Is_page_size_valid( |
---|
247 | unsigned32 page_size |
---|
248 | ) |
---|
249 | { |
---|
250 | return ((page_size != 0) && |
---|
251 | ((page_size % CPU_HEAP_ALIGNMENT) == 0)); |
---|
252 | } |
---|
253 | |
---|
254 | /*PAGE |
---|
255 | * |
---|
256 | * _Heap_Build_flag |
---|
257 | * |
---|
258 | * DESCRIPTION: |
---|
259 | * |
---|
260 | * This function returns the block flag composed of size and in_use_flag. |
---|
261 | * The flag returned is suitable for use as a back or front flag in a |
---|
262 | * heap block. |
---|
263 | */ |
---|
264 | |
---|
265 | RTEMS_INLINE_ROUTINE unsigned32 _Heap_Build_flag ( |
---|
266 | unsigned32 size, |
---|
267 | unsigned32 in_use_flag |
---|
268 | ) |
---|
269 | { |
---|
270 | return size | in_use_flag; |
---|
271 | } |
---|
272 | |
---|
273 | #endif |
---|
274 | /* end of include file */ |
---|