source: rtems/cpukit/sapi/include/rtems/rbheap.h @ 38f8e548

Last change on this file since 38f8e548 was 38f8e548, checked in by Sebastian Huber <sebastian.huber@…>, on 04/10/12 at 09:19:39

rbheap: New files

In the Red-Black Tree Heap the administration data structures are not
contained in the managed memory area. This can be used for example in a
task stack allocator which protects the task stacks from access by other
tasks.

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup RBHeap
5 *
6 * @brief Red-Black Tree Heap API.
7 */
8
9/*
10 * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Obere Lagerstr. 30
14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.com/license/LICENSE.
21 */
22
23#ifndef _RTEMS_RBHEAP_H
24#define _RTEMS_RBHEAP_H
25
26#include <rtems.h>
27#include <rtems/chain.h>
28#include <rtems/rbtree.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34/**
35 * @defgroup RBHeap Red-Black Tree Heap
36 *
37 * @brief Red-Black Tree Heap API.
38 *
39 * In the Red-Black Tree Heap the administration data structures are not
40 * contained in the managed memory area.  This can be used for example in a
41 * task stack allocator which protects the task stacks from access by other
42 * tasks.
43 *
44 * @{
45 */
46
47typedef struct {
48  rtems_chain_node chain_node;
49  rtems_rbtree_node tree_node;
50  uintptr_t begin;
51  uintptr_t size;
52} rtems_rbheap_page;
53
54typedef struct rtems_rbheap_control rtems_rbheap_control;
55
56typedef void (*rtems_rbheap_extend_page_pool)(rtems_rbheap_control *control);
57
58struct rtems_rbheap_control {
59  rtems_chain_control free_chain;
60  rtems_chain_control pool_chain;
61  rtems_rbtree_control page_tree;
62  uintptr_t page_alignment;
63  rtems_rbheap_extend_page_pool extend_page_pool;
64  void *handler_arg;
65};
66
67rtems_status_code rtems_rbheap_initialize(
68  rtems_rbheap_control *control,
69  void *area_begin,
70  uintptr_t area_size,
71  uintptr_t page_alignment,
72  rtems_rbheap_extend_page_pool extend_page_pool,
73  void *handler_arg
74);
75
76void *rtems_rbheap_allocate(rtems_rbheap_control *control, size_t size);
77
78rtems_status_code rtems_rbheap_free(rtems_rbheap_control *control, void *ptr);
79
80static inline rtems_chain_control *rtems_rbheap_get_pool_chain(
81  rtems_rbheap_control *control
82)
83{
84  return &control->pool_chain;
85}
86
87static inline void rtems_rbheap_set_extend_page_pool(
88  rtems_rbheap_control *control,
89  rtems_rbheap_extend_page_pool extend_page_pool
90)
91{
92  control->extend_page_pool = extend_page_pool;
93}
94
95static inline void *rtems_rbheap_get_handler_arg(
96  const rtems_rbheap_control *control
97)
98{
99  return control->handler_arg;
100}
101
102static inline void rtems_rbheap_set_handler_arg(
103  rtems_rbheap_control *control,
104  void *handler_arg
105)
106{
107  control->handler_arg = handler_arg;
108}
109
110void rtems_rbheap_extend_page_pool_never(rtems_rbheap_control *control);
111
112void rtems_rbheap_extend_page_pool_with_malloc(rtems_rbheap_control *control);
113
114/** @} */
115
116/* Private API */
117
118#define rtems_rbheap_page_of_node(node) \
119  rtems_rbtree_container_of(node, rtems_rbheap_page, tree_node)
120
121static inline bool rtems_rbheap_is_page_free(const rtems_rbheap_page *page)
122{
123  return !rtems_chain_is_node_off_chain(&page->chain_node);
124}
125
126#ifdef __cplusplus
127}
128#endif
129
130#endif /* _RTEMS_RBHEAP_H */
Note: See TracBrowser for help on using the repository browser.