summaryrefslogtreecommitdiffstats
path: root/cpukit/score/macros/rtems/score/heap.inl
blob: 39256e865a80297fa05a41d3157fd324cc0813cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*  heap.inl
 *
 *  This file contains the macro implementation of the inlined
 *  routines from the heap handler.
 *
 *  COPYRIGHT (c) 1989-1997.
 *  On-Line Applications Research Corporation (OAR).
 *  Copyright assigned to U.S. Government, 1994.
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.OARcorp.com/rtems/license.html.
 *
 *  $Id$
 */

#ifndef __HEAP_inl
#define __HEAP_inl

#include <rtems/score/address.h>

/*PAGE
 *
 *  _Heap_Head
 */

#define _Heap_Head( _the_heap ) \
  ((Heap_Block *)&(_the_heap)->start)

/*PAGE
 *
 *  _Heap_Tail
 */

#define _Heap_Tail( _the_heap ) \
  ((Heap_Block *)&(_the_heap)->final)

/*PAGE
 *
 *  _Heap_Previous_block
 */

#define _Heap_Previous_block( _the_block ) \
  ( (Heap_Block *) _Addresses_Subtract_offset( \
      (void *)(_the_block), \
      (_the_block)->back_flag & ~ HEAP_BLOCK_USED \
    ) \
  )

/*PAGE
 *
 *  _Heap_Next_block
 */

#define _Heap_Next_block( _the_block ) \
  ( (Heap_Block *) _Addresses_Add_offset( \
      (void *)(_the_block), \
      (_the_block)->front_flag & ~ HEAP_BLOCK_USED \
    ) \
  )

/*PAGE
 *
 *  _Heap_Block_at
 */

#define _Heap_Block_at( _base, _offset ) \
  ( (Heap_Block *) \
     _Addresses_Add_offset( (void *)(_base), (_offset) ) )

/*PAGE
 *
 *  _Heap_User_block_at
 *
 */
 
#define _Heap_User_block_at( _base ) \
  _Heap_Block_at( \
    (_base), \
    -*(((unsigned32 *) (_base)) - 1) + -HEAP_BLOCK_USED_OVERHEAD \
  )

/*PAGE
 *
 *  _Heap_Is_previous_block_free
 */

#define _Heap_Is_previous_block_free( _the_block ) \
  ( !((_the_block)->back_flag & HEAP_BLOCK_USED) )

/*PAGE
 *
 *  _Heap_Is_block_free
 */

#define _Heap_Is_block_free( _the_block ) \
  ( !((_the_block)->front_flag & HEAP_BLOCK_USED) )

/*PAGE
 *
 *  _Heap_Is_block_used
 */

#define _Heap_Is_block_used( _the_block ) \
  ((_the_block)->front_flag & HEAP_BLOCK_USED)

/*PAGE
 *
 *  _Heap_Block_size
 */

#define _Heap_Block_size( _the_block )    \
  ((_the_block)->front_flag & ~HEAP_BLOCK_USED)

/*PAGE
 *
 *  _Heap_Start_of_user_area
 */

#define _Heap_Start_of_user_area( _the_block ) \
  ((void *) &(_the_block)->next)

/*PAGE
 *
 *  _Heap_Is_block_in
 */

#define _Heap_Is_block_in( _the_heap, _the_block ) \
  ( ((_the_block) >= (_the_heap)->start) && \
    ((_the_block) <= (_the_heap)->final) )

/*PAGE
 *
 *  _Heap_Is_page_size_valid
 */

#define _Heap_Is_page_size_valid( _page_size ) \
  ( ((_page_size) != 0) && \
    (((_page_size) % CPU_HEAP_ALIGNMENT) == 0) )

/*PAGE
 *
 *  _Heap_Build_flag
 */

#define _Heap_Build_flag( _size, _in_use_flag ) \
  ( (_size) | (_in_use_flag))

#endif
/* end of include file */