source: rtems/cpukit/score/inline/rtems/score/heap.inl @ d6154c7

4.104.114.84.95
Last change on this file since d6154c7 was d6154c7, checked in by Ralf Corsepius <ralf.corsepius@…>, on Mar 29, 2004 at 4:41:13 PM

2004-03-29 Ralf Corsepius <ralf_corsepius@…>

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