RTEMS: cpukit/include/rtems/rbheap.h Source File

| RTEMS 5.4-rc2

Loading...
Searching...
No Matches
rbheap.h
Go to the documentation of this file.
1
7/*
8 * Copyright (c) 2012 embedded brains GmbH. All rights reserved.
9 *
10 * embedded brains GmbH
11 * Obere Lagerstr. 30
12 * 82178 Puchheim
13 * Germany
14 * <rtems@embedded-brains.de>
15 *
16 * The license and distribution terms for this file may be
17 * found in the file LICENSE in this distribution or at
18 * http://www.rtems.org/license/LICENSE.
19 */
20
21#ifndef _RTEMS_RBHEAP_H
22#define _RTEMS_RBHEAP_H
23
24#include <rtems.h>
25#include <rtems/chain.h>
26#include <rtems/rbtree.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
54 typedef struct {
63 rtems_chain_node chain_node;
64
69 rtems_rbtree_node tree_node;
70
75 uintptr_t begin;
76
80 uintptr_t size;
81} rtems_rbheap_chunk;
82
83typedef struct rtems_rbheap_control rtems_rbheap_control;
84
105 typedef void (*rtems_rbheap_extend_descriptors)(rtems_rbheap_control *control);
106
110 struct rtems_rbheap_control {
114 rtems_chain_control free_chunk_chain;
115
122 rtems_chain_control spare_descriptor_chain;
123
127 rtems_rbtree_control chunk_tree;
128
132 uintptr_t alignment;
133
137 rtems_rbheap_extend_descriptors extend_descriptors;
138
142 void *handler_arg;
143};
144
160 rtems_status_code rtems_rbheap_initialize(
161 rtems_rbheap_control *control,
162 void *area_begin,
163 uintptr_t area_size,
164 uintptr_t alignment,
165 rtems_rbheap_extend_descriptors extend_descriptors,
166 void *handler_arg
167);
168
182void *rtems_rbheap_allocate(rtems_rbheap_control *control, size_t size);
183
196 rtems_status_code rtems_rbheap_free(rtems_rbheap_control *control, void *ptr);
197
198static inline rtems_chain_control *rtems_rbheap_get_spare_descriptor_chain(
199 rtems_rbheap_control *control
200)
201{
202 return &control->spare_descriptor_chain;
203}
204
205static inline void rtems_rbheap_add_to_spare_descriptor_chain(
206 rtems_rbheap_control *control,
207 rtems_rbheap_chunk *chunk
208)
209{
210 rtems_chain_control *chain =
211 rtems_rbheap_get_spare_descriptor_chain(control);
212
213 rtems_chain_initialize_node(&chunk->chain_node);
214 rtems_chain_prepend_unprotected(chain, &chunk->chain_node);
215}
216
217static inline void rtems_rbheap_set_extend_descriptors(
218 rtems_rbheap_control *control,
219 rtems_rbheap_extend_descriptors extend_descriptors
220)
221{
222 control->extend_descriptors = extend_descriptors;
223}
224
225static inline void *rtems_rbheap_get_handler_arg(
226 const rtems_rbheap_control *control
227)
228{
229 return control->handler_arg;
230}
231
232static inline void rtems_rbheap_set_handler_arg(
233 rtems_rbheap_control *control,
234 void *handler_arg
235)
236{
237 control->handler_arg = handler_arg;
238}
239
243void rtems_rbheap_extend_descriptors_never(rtems_rbheap_control *control);
244
248void rtems_rbheap_extend_descriptors_with_malloc(
249 rtems_rbheap_control *control
250);
251
254/* Private API */
255
256#define rtems_rbheap_chunk_of_node(node) \
257 RTEMS_CONTAINER_OF(node, rtems_rbheap_chunk, tree_node)
258
259static inline bool rtems_rbheap_is_chunk_free(const rtems_rbheap_chunk *chunk)
260{
261 return !rtems_chain_is_node_off_chain(&chunk->chain_node);
262}
263
264#ifdef __cplusplus
265}
266#endif
267
268#endif /* _RTEMS_RBHEAP_H */
chain.h
Chain API.
rtems_chain_prepend_unprotected
RTEMS_INLINE_ROUTINE void rtems_chain_prepend_unprotected(rtems_chain_control *the_chain, rtems_chain_node *the_node)
Prepend a node (unprotected).
Definition: chain.h:714
rtems_chain_initialize_node
RTEMS_INLINE_ROUTINE void rtems_chain_initialize_node(rtems_chain_node *node)
Initializes a chain node.
Definition: chain.h:198
rtems_chain_is_node_off_chain
RTEMS_INLINE_ROUTINE bool rtems_chain_is_node_off_chain(const rtems_chain_node *node)
Is the node off chain.
Definition: chain.h:216
rtems_rbtree_control
RBTree_Control rtems_rbtree_control
Definition: rbtree.h:55
rtems_status_code
rtems_status_code
Classic API Status.
Definition: status.h:43
rtems_rbheap_initialize
rtems_status_code rtems_rbheap_initialize(rtems_rbheap_control *control, void *area_begin, uintptr_t area_size, uintptr_t alignment, rtems_rbheap_extend_descriptors extend_descriptors, void *handler_arg)
Initializes the red-black tree heap control.
Definition: rbheap.c:91
rtems_rbheap_free
rtems_status_code rtems_rbheap_free(rtems_rbheap_control *control, void *ptr)
Frees a chunk of memory ptr allocated from the red-black tree heap control.
Definition: rbheap.c:243
rtems_rbheap_extend_descriptors_never
void rtems_rbheap_extend_descriptors_never(rtems_rbheap_control *control)
Chunk descriptor extend handler that does nothing.
Definition: rbheap.c:270
rtems_rbheap_extend_descriptors
void(* rtems_rbheap_extend_descriptors)(rtems_rbheap_control *control)
Handler to extend the available chunk descriptors.
Definition: rbheap.h:105
rtems_rbheap_extend_descriptors_with_malloc
void rtems_rbheap_extend_descriptors_with_malloc(rtems_rbheap_control *control)
Chunk descriptor extend handler that uses malloc().
Definition: rbheap.c:275
rtems_rbheap_allocate
void * rtems_rbheap_allocate(rtems_rbheap_control *control, size_t size)
Allocates a chunk of memory of at least size bytes from the red-black tree heap control.
Definition: rbheap.c:165
rbtree.h
Constants and Structures Associated with the RBTree API in RTEMS.
rtems.h
Chain_Node_struct
Definition: chain.h:68
RBTree_Node
Red-black tree node.
Definition: rbtree.h:55
control
Definition: intercom.c:74
rtems_rbheap_chunk
Red-black heap chunk descriptor.
Definition: rbheap.h:54
rtems_rbheap_chunk::size
uintptr_t size
Definition: rbheap.h:80
rtems_rbheap_chunk::chain_node
rtems_chain_node chain_node
Definition: rbheap.h:63
rtems_rbheap_chunk::begin
uintptr_t begin
Definition: rbheap.h:75
rtems_rbheap_chunk::tree_node
rtems_rbtree_node tree_node
Definition: rbheap.h:69
rtems_rbheap_control
Red-black heap control.
Definition: rbheap.h:110
rtems_rbheap_control::spare_descriptor_chain
rtems_chain_control spare_descriptor_chain
Definition: rbheap.h:122
rtems_rbheap_control::free_chunk_chain
rtems_chain_control free_chunk_chain
Definition: rbheap.h:114
rtems_rbheap_control::alignment
uintptr_t alignment
Definition: rbheap.h:132
rtems_rbheap_control::extend_descriptors
rtems_rbheap_extend_descriptors extend_descriptors
Definition: rbheap.h:137
rtems_rbheap_control::chunk_tree
rtems_rbtree_control chunk_tree
Definition: rbheap.h:127
rtems_rbheap_control::handler_arg
void * handler_arg
Definition: rbheap.h:142
Chain_Control
Definition: chain.h:86