RTEMS 6.1-rc4
Loading...
Searching...
No Matches
rbheap.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
11/*
12 * Copyright (c) 2012 embedded brains GmbH & Co. KG
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#ifndef _RTEMS_RBHEAP_H
37#define _RTEMS_RBHEAP_H
38
39#include <rtems.h>
40#include <rtems/chain.h>
41#include <rtems/rbtree.h>
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
70typedef struct {
80
86
91 uintptr_t begin;
92
96 uintptr_t size;
98
100
122
131
139
144
148 uintptr_t alignment;
149
154
159};
160
178 void *area_begin,
179 uintptr_t area_size,
180 uintptr_t alignment,
181 rtems_rbheap_extend_descriptors extend_descriptors,
182 void *handler_arg
183);
184
199
213
214static inline rtems_chain_control *rtems_rbheap_get_spare_descriptor_chain(
216)
217{
218 return &control->spare_descriptor_chain;
219}
220
221static inline void rtems_rbheap_add_to_spare_descriptor_chain(
223 rtems_rbheap_chunk *chunk
224)
225{
226 rtems_chain_control *chain =
227 rtems_rbheap_get_spare_descriptor_chain(control);
228
229 rtems_chain_initialize_node(&chunk->chain_node);
230 rtems_chain_prepend_unprotected(chain, &chunk->chain_node);
231}
232
233static inline void rtems_rbheap_set_extend_descriptors(
235 rtems_rbheap_extend_descriptors extend_descriptors
236)
237{
238 control->extend_descriptors = extend_descriptors;
239}
240
241static inline void *rtems_rbheap_get_handler_arg(
243)
244{
245 return control->handler_arg;
246}
247
248static inline void rtems_rbheap_set_handler_arg(
250 void *handler_arg
251)
252{
253 control->handler_arg = handler_arg;
254}
255
260
266);
267
270/* Private API */
271
272#define rtems_rbheap_chunk_of_node(node) \
273 RTEMS_CONTAINER_OF(node, rtems_rbheap_chunk, tree_node)
274
275static inline bool rtems_rbheap_is_chunk_free(const rtems_rbheap_chunk *chunk)
276{
277 return !rtems_chain_is_node_off_chain(&chunk->chain_node);
278}
279
280#ifdef __cplusplus
281}
282#endif
283
284#endif /* _RTEMS_RBHEAP_H */
This header file provides the Chains API.
rtems_status_code
This enumeration provides status codes for directives of the Classic API.
Definition: status.h:85
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:107
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:259
void rtems_rbheap_extend_descriptors_never(rtems_rbheap_control *control)
Chunk descriptor extend handler that does nothing.
Definition: rbheap.c:286
void(* rtems_rbheap_extend_descriptors)(rtems_rbheap_control *control)
Handler to extend the available chunk descriptors.
Definition: rbheap.h:121
void rtems_rbheap_extend_descriptors_with_malloc(rtems_rbheap_control *control)
Chunk descriptor extend handler that uses malloc().
Definition: rbheap.c:291
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:181
RBTree_Control rtems_rbtree_control
Definition: rbtree.h:72
This header file provides the Red-Black Trees API.
This header file defines the RTEMS Classic API.
This structure represents a chain node.
Definition: chain.h:78
Red-black tree node.
Definition: rbtree.h:73
Definition: intercom.c:87
Red-black heap chunk descriptor.
Definition: rbheap.h:70
uintptr_t size
Definition: rbheap.h:96
rtems_chain_node chain_node
Definition: rbheap.h:79
uintptr_t begin
Definition: rbheap.h:91
rtems_rbtree_node tree_node
Definition: rbheap.h:85
Red-black heap control.
Definition: rbheap.h:126
rtems_chain_control spare_descriptor_chain
Definition: rbheap.h:138
rtems_chain_control free_chunk_chain
Definition: rbheap.h:130
uintptr_t alignment
Definition: rbheap.h:148
rtems_rbheap_extend_descriptors extend_descriptors
Definition: rbheap.h:153
rtems_rbtree_control chunk_tree
Definition: rbheap.h:143
void * handler_arg
Definition: rbheap.h:158
This union represents a chain control block.
Definition: chain.h:96