RTEMS CPU Kit with SuperCore  4.11.3
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
29 extern "C" {
30 #endif
31 
54 typedef struct {
64 
70 
75  uintptr_t begin;
76 
80  uintptr_t size;
82 
84 
106 
115 
123 
128 
132  uintptr_t alignment;
133 
138 
142  void *handler_arg;
143 };
144 
161  rtems_rbheap_control *control,
162  void *area_begin,
163  uintptr_t area_size,
164  uintptr_t alignment,
166  void *handler_arg
167 );
168 
182 void *rtems_rbheap_allocate(rtems_rbheap_control *control, size_t size);
183 
197 
198 static 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 
205 static 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 
214 }
215 
216 static inline void rtems_rbheap_set_extend_descriptors(
217  rtems_rbheap_control *control,
219 )
220 {
222 }
223 
224 static inline void *rtems_rbheap_get_handler_arg(
225  const rtems_rbheap_control *control
226 )
227 {
228  return control->handler_arg;
229 }
230 
231 static inline void rtems_rbheap_set_handler_arg(
232  rtems_rbheap_control *control,
233  void *handler_arg
234 )
235 {
236  control->handler_arg = handler_arg;
237 }
238 
243 
248  rtems_rbheap_control *control
249 );
250 
253 /* Private API */
254 
255 #define rtems_rbheap_chunk_of_node(node) \
256  RTEMS_CONTAINER_OF(node, rtems_rbheap_chunk, tree_node)
257 
258 static inline bool rtems_rbheap_is_chunk_free(const rtems_rbheap_chunk *chunk)
259 {
260  return !rtems_chain_is_node_off_chain(&chunk->chain_node);
261 }
262 
263 #ifdef __cplusplus
264 }
265 #endif
266 
267 #endif /* _RTEMS_RBHEAP_H */
rtems_chain_control spare_descriptor_chain
Chain of free chunk descriptors.
Definition: rbheap.h:122
This is used to manage each element (node) which is placed on a chain.
Definition: chain.h:65
uintptr_t begin
Begin address of the chunk.
Definition: rbheap.h:75
rtems_rbtree_control chunk_tree
Tree of chunks representing the state of the managed memory area.
Definition: rbheap.h:127
Red-black heap control.
Definition: rbheap.h:110
This is used to manage a chain.
Definition: chain.h:83
Red-black heap chunk descriptor.
Definition: rbheap.h:54
void rtems_rbheap_extend_descriptors_never(rtems_rbheap_control *control)
Chunk descriptor extend handler that does nothing.
Definition: rbheap.c:265
rtems_chain_node chain_node
This chain node can be used in two chains.
Definition: rbheap.h:63
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:90
rtems_rbtree_node tree_node
Tree node for chunks that represent a part of the managed memory area.
Definition: rbheap.h:69
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:737
uintptr_t size
Size of the chunk in bytes.
Definition: rbheap.h:80
rtems_status_code
Classic API Status.
Definition: status.h:46
RTEMS_INLINE_ROUTINE bool rtems_chain_is_node_off_chain(const rtems_chain_node *node)
Is the node off chain.
Definition: chain.h:201
void(* rtems_rbheap_extend_descriptors)(rtems_rbheap_control *control)
Handler to extend the available chunk descriptors.
Definition: rbheap.h:105
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:164
rtems_rbheap_extend_descriptors extend_descriptors
Handler to extend the available chunk descriptors.
Definition: rbheap.h:137
void * handler_arg
User specified argument handler for private handler data.
Definition: rbheap.h:142
This is used to manage a RBT.
Definition: rbtree.h:138
void rtems_rbheap_extend_descriptors_with_malloc(rtems_rbheap_control *control)
Chunk descriptor extend handler that uses malloc().
Definition: rbheap.c:270
Chain API.
Constants and Structures Associated with the RBTree API in RTEMS.
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:238
This is used to manage each element (node) which is placed on a RBT.
Definition: rbtree.h:75
rtems_chain_control free_chunk_chain
Chain of free chunks in the managed memory area.
Definition: rbheap.h:114
uintptr_t alignment
Minimum chunk begin alignment in bytes.
Definition: rbheap.h:132