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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [exec/] [score/] [include/] [rtems/] [score/] [heap.h] - Blame information for rev 30

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

Line No. Rev Author Line
1 30 unneback
/*  heap.h
2
 *
3
 *  This include file contains the information pertaining to the Heap
4
 *  Handler.  A heap is a doubly linked list of variable size
5
 *  blocks which are allocated using the first fit method.  Garbage
6
 *  collection is performed each time a block is returned to the heap by
7
 *  coalescing neighbor blocks.  Control information for both allocated
8
 *  and unallocated blocks is contained in the heap space.  A heap header
9
 *  contains control information for the heap.
10
 *
11
 *  COPYRIGHT (c) 1989-1999.
12
 *  On-Line Applications Research Corporation (OAR).
13
 *
14
 *  The license and distribution terms for this file may be
15
 *  found in the file LICENSE in this distribution or at
16
 *  http://www.OARcorp.com/rtems/license.html.
17
 *
18
 *  $Id: heap.h,v 1.2 2001-09-27 11:59:32 chris Exp $
19
 */
20
 
21
#ifndef __RTEMS_HEAP_h
22
#define __RTEMS_HEAP_h
23
 
24
#ifdef __cplusplus
25
extern "C" {
26
#endif
27
 
28
/*
29
 *  Status codes for heap_extend
30
 */
31
 
32
typedef enum {
33
  HEAP_EXTEND_SUCCESSFUL,
34
  HEAP_EXTEND_ERROR,
35
  HEAP_EXTEND_NOT_IMPLEMENTED
36
}  Heap_Extend_status;
37
 
38
/*
39
 *  Constants used in the size/used field of each heap block to
40
 *  indicate when a block is free or in use.
41
 */
42
 
43
#define HEAP_BLOCK_USED    1           /* indicates block is in use */
44
#define HEAP_BLOCK_FREE    0           /* indicates block is free */
45
 
46
/*
47
 *  The size/used field value for the dummy front and back flags.
48
 */
49
 
50
#define HEAP_DUMMY_FLAG    (0 + HEAP_BLOCK_USED)
51
 
52
/*
53
 *  The following constants reflect various requirements of the
54
 *  heap data structures which impact the management of a heap.
55
 *
56
 * NOTE:   Because free block overhead is greater than used block
57
 *         overhead AND a portion of the allocated space is from
58
 *         the extra free block overhead, the absolute lower bound
59
 *         of the minimum fragment size is equal to the size of
60
 *         the free block overhead.
61
 */
62
 
63
#define HEAP_OVERHEAD \
64
  (sizeof( unsigned32 ) * 2)         /* size dummy first and last blocks */
65
#define HEAP_BLOCK_USED_OVERHEAD \
66
  (sizeof( void * ) * 2)             /* num bytes overhead in used block */
67
#define HEAP_MINIMUM_SIZE \
68
  (HEAP_OVERHEAD + sizeof (Heap_Block))
69
                                     /* min number of bytes the user may */
70
                                     /*   specify for the heap size      */
71
 
72
/*
73
 *  The following defines the data structure used to manage
74
 *  individual blocks in a heap.   When the block is allocated, the
75
 *  next and previous fields are not used by the Heap Handler
76
 *  and thus the address returned for the block starts at
77
 *  the address of the next field.
78
 *
79
 *  NOTE:  The next and previous pointers are only valid when the
80
 *         block is free.  Caution must be exercised to insure that
81
 *         allocated blocks are large enough to contain them and
82
 *         that they are not accidentally overwritten when the
83
 *         block is actually allocated.
84
 */
85
 
86
typedef struct Heap_Block_struct Heap_Block;
87
 
88
struct Heap_Block_struct {
89
  unsigned32  back_flag;   /* size and status of prev block */
90
  unsigned32  front_flag;  /* size and status of block */
91
  Heap_Block *next;        /* pointer to next block */
92
  Heap_Block *previous;    /* pointer to previous block */
93
};
94
 
95
/*
96
 *  The following defines the control block used to manage each heap.
97
 *
98
 *  NOTE:
99
 *
100
 *  This structure is layed out such that it can be used a a dummy
101
 *  first and last block on the free block chain.  The extra padding
102
 *  insures the dummy last block is the correct size.
103
 *
104
 *  The first Heap_Block starts at first while the second starts at
105
 *  final.  This is effectively the same trick as is used in the Chain
106
 *  Handler.
107
 */
108
 
109
typedef struct {
110
  Heap_Block *start;       /* first valid block address in heap */
111
  Heap_Block *final;       /* last valid block address in heap */
112
 
113
  Heap_Block *first;       /* pointer to first block in heap */
114
  Heap_Block *permanent_null;  /* always NULL pointer */
115
  Heap_Block *last;        /* pointer to last block in heap */
116
  unsigned32  page_size;   /* allocation unit */
117
  unsigned32  reserved;
118
}   Heap_Control;
119
 
120
/*
121
 *  _Heap_Initialize
122
 *
123
 *  DESCRIPTION:
124
 *
125
 *  This routine initializes the_heap record to manage the
126
 *  contiguous heap of size bytes which starts at starting_address.
127
 *  Blocks of memory are allocated from the heap in multiples of
128
 *  page_size byte units.
129
 */
130
 
131
unsigned32 _Heap_Initialize(
132
  Heap_Control *the_heap,
133
  void         *starting_address,
134
  unsigned32    size,
135
  unsigned32    page_size
136
);
137
 
138
/*
139
 *  _Heap_Extend
140
 *
141
 *  DESCRIPTION:
142
 *
143
 *  This routine grows the_heap memory area using the size bytes which
144
 *  begin at starting_address.
145
 */
146
 
147
Heap_Extend_status _Heap_Extend(
148
  Heap_Control *the_heap,
149
  void         *starting_address,
150
  unsigned32    size,
151
  unsigned32   *amount_extended
152
);
153
 
154
/*
155
 *  _Heap_Allocate
156
 *
157
 *  DESCRIPTION:
158
 *
159
 *  DESCRIPTION:
160
 *
161
 *  This function attempts to allocate a block of size bytes from
162
 *  the_heap.  If insufficient memory is free in the_heap to allocate
163
 *  a  block of the requested size, then NULL is returned.
164
 */
165
 
166
void *_Heap_Allocate(
167
  Heap_Control *the_heap,
168
  unsigned32    size
169
);
170
 
171
/*
172
 *  _Heap_Size_of_user_area
173
 *
174
 *  DESCRIPTION:
175
 *
176
 *  This kernel routine sets size to the size of the given heap block.
177
 *  It returns TRUE if the starting_address is in the heap, and FALSE
178
 *  otherwise.
179
 */
180
 
181
boolean _Heap_Size_of_user_area(
182
  Heap_Control        *the_heap,
183
  void                *starting_address,
184
  unsigned32          *size
185
);
186
 
187
/*
188
 *  _Heap_Free
189
 *
190
 *  DESCRIPTION:
191
 *
192
 *  This routine returns the block of memory which begins
193
 *  at starting_address to the_heap.  Any coalescing which is
194
 *  possible with the freeing of this routine is performed.
195
 */
196
 
197
boolean _Heap_Free(
198
  Heap_Control *the_heap,
199
  void         *start_address
200
);
201
 
202
/*
203
 *  _Heap_Walk
204
 *
205
 *  DESCRIPTION:
206
 *
207
 *  This routine walks the heap to verify its integrity.
208
 */
209
 
210
void _Heap_Walk(
211
  Heap_Control *the_heap,
212
  int           source,
213
  boolean       do_dump
214
);
215
 
216
#ifndef __RTEMS_APPLICATION__
217
#include <rtems/score/heap.inl>
218
#endif
219
 
220
#ifdef __cplusplus
221
}
222
#endif
223
 
224
#endif
225
/* end of include file */

powered by: WebSVN 2.1.0

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