OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [exec/] [score/] [inline/] [rtems/] [score/] [heap.inl] - Blame information for rev 621

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*  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.OARcorp.com/rtems/license.html.
12
 *
13
 *  $Id: heap.inl,v 1.2 2001-09-27 11:59:34 chris Exp $
14
 */
15
 
16
#ifndef __HEAP_inl
17
#define __HEAP_inl
18
 
19
#include 
20
 
21
/*PAGE
22
 *
23
 *  _Heap_Head
24
 *
25
 *  DESCRIPTION:
26
 *
27
 *  This function returns the head of the specified heap.
28
 */
29
 
30
RTEMS_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
 
46
RTEMS_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
 
63
RTEMS_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
 
85
RTEMS_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
 
105
RTEMS_INLINE_ROUTINE Heap_Block *_Heap_Block_at(
106
  void       *base,
107
  unsigned32  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
 
122
RTEMS_INLINE_ROUTINE Heap_Block *_Heap_User_block_at(
123
  void       *base
124
)
125
{
126
  unsigned32         offset;
127
 
128
  offset = *(((unsigned32 *) 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
 
142
RTEMS_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
 
158
RTEMS_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
 
175
RTEMS_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
 
191
RTEMS_INLINE_ROUTINE unsigned32 _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
 
208
RTEMS_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
 
225
RTEMS_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
 
245
RTEMS_INLINE_ROUTINE boolean _Heap_Is_page_size_valid(
246
  unsigned32 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
 
264
RTEMS_INLINE_ROUTINE unsigned32 _Heap_Build_flag (
265
  unsigned32 size,
266
  unsigned32 in_use_flag
267
)
268
{
269
  return  size | in_use_flag;
270
}
271
 
272
#endif
273
/* end of include file */

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.