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, 1990, 1991, 1992, 1993, 1994. |
---|
7 | * On-Line Applications Research Corporation (OAR). |
---|
8 | * All rights assigned to U.S. Government, 1994. |
---|
9 | * |
---|
10 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
11 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
12 | * notice must appear in all copies of this file and its derivatives. |
---|
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 | */ |
---|
27 | |
---|
28 | STATIC INLINE Heap_Block *_Heap_Head ( |
---|
29 | Heap_Control *the_heap |
---|
30 | ) |
---|
31 | { |
---|
32 | return (Heap_Block *)&the_heap->start; |
---|
33 | } |
---|
34 | |
---|
35 | /*PAGE |
---|
36 | * |
---|
37 | * _Heap_Tail |
---|
38 | * |
---|
39 | */ |
---|
40 | |
---|
41 | STATIC INLINE Heap_Block *_Heap_Tail ( |
---|
42 | Heap_Control *the_heap |
---|
43 | ) |
---|
44 | { |
---|
45 | return (Heap_Block *)&the_heap->final; |
---|
46 | } |
---|
47 | |
---|
48 | /*PAGE |
---|
49 | * |
---|
50 | * _Heap_Previous_block |
---|
51 | * |
---|
52 | */ |
---|
53 | |
---|
54 | STATIC INLINE Heap_Block *_Heap_Previous_block ( |
---|
55 | Heap_Block *the_block |
---|
56 | ) |
---|
57 | { |
---|
58 | return (Heap_Block *) _Addresses_Subtract_offset( |
---|
59 | (void *)the_block, |
---|
60 | the_block->back_flag & ~ HEAP_BLOCK_USED |
---|
61 | ); |
---|
62 | } |
---|
63 | |
---|
64 | /*PAGE |
---|
65 | * |
---|
66 | * _Heap_Next_block |
---|
67 | * |
---|
68 | * NOTE: Next_block assumes that the block is free. |
---|
69 | */ |
---|
70 | |
---|
71 | STATIC INLINE Heap_Block *_Heap_Next_block ( |
---|
72 | Heap_Block *the_block |
---|
73 | ) |
---|
74 | { |
---|
75 | return (Heap_Block *) _Addresses_Add_offset( |
---|
76 | (void *)the_block, |
---|
77 | the_block->front_flag & ~ HEAP_BLOCK_USED |
---|
78 | ); |
---|
79 | } |
---|
80 | |
---|
81 | /*PAGE |
---|
82 | * |
---|
83 | * _Heap_Block_at |
---|
84 | * |
---|
85 | */ |
---|
86 | |
---|
87 | STATIC INLINE Heap_Block *_Heap_Block_at( |
---|
88 | void *base, |
---|
89 | unsigned32 offset |
---|
90 | ) |
---|
91 | { |
---|
92 | return (Heap_Block *) _Addresses_Add_offset( (void *)base, offset ); |
---|
93 | } |
---|
94 | |
---|
95 | /*PAGE |
---|
96 | * |
---|
97 | * _Heap_User_block_at |
---|
98 | * |
---|
99 | */ |
---|
100 | |
---|
101 | STATIC INLINE Heap_Block *_Heap_User_block_at( |
---|
102 | void *base |
---|
103 | ) |
---|
104 | { |
---|
105 | unsigned32 offset; |
---|
106 | |
---|
107 | offset = *(((unsigned32 *) base) - 1); |
---|
108 | return _Heap_Block_at( base, -offset + -HEAP_BLOCK_USED_OVERHEAD); |
---|
109 | } |
---|
110 | |
---|
111 | /*PAGE |
---|
112 | * |
---|
113 | * _Heap_Is_previous_block_free |
---|
114 | * |
---|
115 | */ |
---|
116 | |
---|
117 | STATIC INLINE boolean _Heap_Is_previous_block_free ( |
---|
118 | Heap_Block *the_block |
---|
119 | ) |
---|
120 | { |
---|
121 | return !(the_block->back_flag & HEAP_BLOCK_USED); |
---|
122 | } |
---|
123 | |
---|
124 | /*PAGE |
---|
125 | * |
---|
126 | * _Heap_Is_block_free |
---|
127 | * |
---|
128 | */ |
---|
129 | |
---|
130 | STATIC INLINE boolean _Heap_Is_block_free ( |
---|
131 | Heap_Block *the_block |
---|
132 | ) |
---|
133 | { |
---|
134 | return !(the_block->front_flag & HEAP_BLOCK_USED); |
---|
135 | } |
---|
136 | |
---|
137 | /*PAGE |
---|
138 | * |
---|
139 | * _Heap_Is_block_used |
---|
140 | * |
---|
141 | */ |
---|
142 | |
---|
143 | STATIC INLINE boolean _Heap_Is_block_used ( |
---|
144 | Heap_Block *the_block |
---|
145 | ) |
---|
146 | { |
---|
147 | return (the_block->front_flag & HEAP_BLOCK_USED); |
---|
148 | } |
---|
149 | |
---|
150 | /*PAGE |
---|
151 | * |
---|
152 | * _Heap_Block_size |
---|
153 | * |
---|
154 | */ |
---|
155 | |
---|
156 | STATIC INLINE unsigned32 _Heap_Block_size ( |
---|
157 | Heap_Block *the_block |
---|
158 | ) |
---|
159 | { |
---|
160 | return (the_block->front_flag & ~HEAP_BLOCK_USED); |
---|
161 | } |
---|
162 | |
---|
163 | /*PAGE |
---|
164 | * |
---|
165 | * _Heap_Start_of_user_area |
---|
166 | * |
---|
167 | */ |
---|
168 | |
---|
169 | STATIC INLINE void *_Heap_Start_of_user_area ( |
---|
170 | Heap_Block *the_block |
---|
171 | ) |
---|
172 | { |
---|
173 | return (void *) &the_block->next; |
---|
174 | } |
---|
175 | |
---|
176 | /*PAGE |
---|
177 | * |
---|
178 | * _Heap_Is_block_in |
---|
179 | * |
---|
180 | */ |
---|
181 | |
---|
182 | STATIC INLINE boolean _Heap_Is_block_in ( |
---|
183 | Heap_Control *the_heap, |
---|
184 | Heap_Block *the_block |
---|
185 | ) |
---|
186 | { |
---|
187 | return _Addresses_Is_in_range( the_block, the_heap->start, the_heap->final ); |
---|
188 | } |
---|
189 | |
---|
190 | /*PAGE |
---|
191 | * |
---|
192 | * _Heap_Is_page_size_valid |
---|
193 | * |
---|
194 | */ |
---|
195 | |
---|
196 | STATIC INLINE boolean _Heap_Is_page_size_valid( |
---|
197 | unsigned32 page_size |
---|
198 | ) |
---|
199 | { |
---|
200 | return ((page_size != 0) && |
---|
201 | ((page_size % CPU_HEAP_ALIGNMENT) == 0)); |
---|
202 | } |
---|
203 | |
---|
204 | /*PAGE |
---|
205 | * |
---|
206 | * _Heap_Build_flag |
---|
207 | * |
---|
208 | */ |
---|
209 | |
---|
210 | STATIC INLINE unsigned32 _Heap_Build_flag ( |
---|
211 | unsigned32 size, |
---|
212 | unsigned32 in_use_flag |
---|
213 | ) |
---|
214 | { |
---|
215 | return size | in_use_flag; |
---|
216 | } |
---|
217 | |
---|
218 | #endif |
---|
219 | /* end of include file */ |
---|