source: rtems/cpukit/score/macros/rtems/score/heap.inl @ 962e894f

4.104.114.84.95
Last change on this file since 962e894f was 962e894f, checked in by Joel Sherrill <joel.sherrill@…>, on 01/20/05 at 18:22:29

2005-01-20 Sergei Organov <osv@…>

PR 536/rtems
Heap manager re-implementation to consume less memory and still satisfy
alignment requirements.


  • score/src/heap.c, score/src/heapallocate.c, score/src/heapextend.c, score/src/heapfree.c, score/src/heapgetinfo.c, score/src/heapgetfreeinfo.c, core/src/heapsizeofuserarea.c, score/src/heapwalk.c, core/macros/rtems/score/heap.inl, score/inline/rtems/score/heap.inl, score/include/rtems/score/heap.h: Reimplemented.
  • score/src/heapallocatealigned.c: new file
  • score/Makefile.am: HEAP_C_FILES: add score/src/heapallocatealigned.c
  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*  heap.inl
2 *
3 *  This file contains the macro 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/*
20 * WARNING: this file is only visually checked against
21 * '../../../inline/rtems/score/heap.inl'. Use those file for reference
22 * if encounter problems.
23 */
24
25#include <rtems/score/address.h>
26
27/*PAGE
28 *
29 *  _Heap_Head
30 */
31
32#define _Heap_Head( _the_heap ) (&(_the_heap)->free_list)
33
34/*PAGE
35 *
36 *  _Heap_Tail
37 */
38
39#define _Heap_Tail( _the_heap ) (&(_the_heap)->free_list)
40
41/*PAGE
42 *
43 *  _Heap_First
44 */
45
46#define _Heap_First( _the_heap ) (_Heap_Head(_the_heap)->next)
47
48/*PAGE
49 *
50 *  _Heap_Last
51 */
52
53#define _Heap_Last( _the_heap )  (_Heap_Tail(_the_heap)->prev)
54
55/*PAGE
56 *
57 *  _Heap_Block_remove
58 *
59 */
60
61#define _Heap_Block_remove( _the_block ) \
62  do { \
63    Heap_Block *block = (_the_block); \
64    Heap_Block *next = block->next; \
65    Heap_Block *prev = block->prev; \
66    prev->next = next; \
67    next->prev = prev; \
68  } while(0)
69
70/*PAGE
71 *
72 *  _Heap_Block_replace
73 *
74 */
75
76#define _Heap_Block_replace( _old_block,  _new_block ) \
77  do { \
78    Heap_Block *block = (_old_block); \
79    Heap_Block *next = block->next; \
80    Heap_Block *prev = block->prev; \
81    block = (_new_block); \
82    block->next = next; \
83    block->prev = prev; \
84    next->prev = prev->next = block; \
85  } while(0)
86
87/*PAGE
88 *
89 *  _Heap_Block_insert_after
90 *
91 */
92
93#define _Heap_Block_insert_after(  _prev_block, _the_block ) \
94  do { \
95    Heap_Block *prev = (_prev_block); \
96    Heap_Block *block = (_the_block); \
97    Heap_Block *next = prev->next; \
98    block->next  = next; \
99    block->prev  = prev; \
100    next->prev = prev->next = block; \
101  } while(0)
102
103/*PAGE
104 *
105 *  _Heap_Is_aligned
106 */
107
108#define _Heap_Is_aligned( _value, _alignment ) \
109  (((_value) % (_alignment)) == 0)
110
111/*PAGE
112 *
113 *  _Heap_Align_up
114 */
115
116#define _Heap_Align_up( _value, _alignment ) \
117  do { \
118    unsigned32 v = *(_value); \
119    unsigned32 a = (_alignment); \
120    unsigned32 r = v % a; \
121    *(_value) = r ? v - r + a : v; \
122  } while(0)
123
124/*PAGE
125 *
126 *  _Heap_Align_down
127 */
128
129#define _Heap_Align_down( _value, _alignment ) \
130  do { \
131    unsigned32 v = *(_value); \
132    *(_value) = v - (v % (_alignment)); \
133  } while(0)
134
135/*PAGE
136 *
137 *  _Heap_Is_aligned_ptr
138 */
139
140#define _Heap_Is_aligned_ptr( _ptr, _alignment ) \
141  ((_H_p2u(_ptr) % (_alignment)) == 0)
142
143/*PAGE
144 *
145 *  _Heap_Align_up_uptr
146 */
147
148#define _Heap_Align_up_uptr( _value, _alignment ) \
149  do { \
150    _H_uptr_t v = *(_value); \
151    unsigned32 a = (_alignment); \
152    _H_uptr_t r = v % a; \
153    *(_value) = r ? v - r + a : v; \
154  } while(0)
155
156/*PAGE
157 *
158 *  _Heap_Align_down_uptr
159 */
160
161#define _Heap_Align_down_uptr( _value, _alignment ) \
162  do { \
163    _H_uptr_t v = *(_value); \
164    *(_value) = v - (v % (_alignment)); \
165  } while(0)
166
167/*PAGE
168 *
169 *  _Heap_Block_at
170 */
171
172#define _Heap_Block_at( _base, _offset ) \
173  ( (Heap_Block *) _Addresses_Add_offset( (_base), (_offset) ) )
174
175/*PAGE
176 *
177 *  _Heap_User_area
178 */
179
180#define _Heap_User_area( _the_block ) \
181  ((void *) _Addresses_Add_offset( (_the_block), HEAP_BLOCK_USER_OFFSET ))
182
183/*PAGE
184 *
185 *  _Heap_Start_of_block
186 */
187 
188#define _Heap_Start_of_block( _the_heap, _base, _the_block_ptr ) \
189  do { \
190    _H_uptr_t addr = _H_p2u(_base); \
191    _Heap_Align_down( &addr, (_the_heap)->page_size ); \
192    *(_the_block_ptr) = (Heap_Block *)(addr - HEAP_BLOCK_USER_OFFSET); \
193  } while(0)
194
195/*PAGE
196 *
197 *  _Heap_Is_prev_used
198 */
199
200#define _Heap_Is_prev_used( _the_block ) \
201  ((_the_block)->size & HEAP_PREV_USED)
202
203/*PAGE
204 *
205 *  _Heap_Block_size
206 */
207
208#define _Heap_Block_size( _the_block )    \
209  ((_the_block)->size & ~HEAP_PREV_USED)
210
211/*PAGE
212 *
213 *  _Heap_Is_block_in
214 */
215
216#define _Heap_Is_block_in( _the_heap, _the_block ) \
217  ( _Addresses_Is_in_range( (_the_block), \
218    (_the_heap)->start, (_the_heap)->final ) )
219
220#endif
221/* end of include file */
Note: See TracBrowser for help on using the repository browser.