|
RTEMS CPU Kit with SuperCore
4.10.99.0
|
00001 00007 /* 00008 * Copyright (c) 2012 embedded brains GmbH. All rights reserved. 00009 * 00010 * embedded brains GmbH 00011 * Obere Lagerstr. 30 00012 * 82178 Puchheim 00013 * Germany 00014 * <rtems@embedded-brains.de> 00015 * 00016 * The license and distribution terms for this file may be 00017 * found in the file LICENSE in this distribution or at 00018 * http://www.rtems.com/license/LICENSE. 00019 */ 00020 00021 #ifndef _RTEMS_RBHEAP_H 00022 #define _RTEMS_RBHEAP_H 00023 00024 #include <rtems.h> 00025 #include <rtems/chain.h> 00026 #include <rtems/rbtree.h> 00027 00028 #ifdef __cplusplus 00029 extern "C" { 00030 #endif 00031 00054 typedef struct { 00063 rtems_chain_node chain_node; 00064 00069 rtems_rbtree_node tree_node; 00070 00075 uintptr_t begin; 00076 00080 uintptr_t size; 00081 } rtems_rbheap_chunk; 00082 00083 typedef struct rtems_rbheap_control rtems_rbheap_control; 00084 00105 typedef void (*rtems_rbheap_extend_descriptors)(rtems_rbheap_control *control); 00106 00110 struct rtems_rbheap_control { 00114 rtems_chain_control free_chunk_chain; 00115 00122 rtems_chain_control spare_descriptor_chain; 00123 00127 rtems_rbtree_control chunk_tree; 00128 00132 uintptr_t alignment; 00133 00137 rtems_rbheap_extend_descriptors extend_descriptors; 00138 00142 void *handler_arg; 00143 }; 00144 00161 rtems_status_code rtems_rbheap_initialize( 00162 rtems_rbheap_control *control, 00163 void *area_begin, 00164 uintptr_t area_size, 00165 uintptr_t alignment, 00166 rtems_rbheap_extend_descriptors extend_descriptors, 00167 void *handler_arg 00168 ); 00169 00183 void *rtems_rbheap_allocate(rtems_rbheap_control *control, size_t size); 00184 00197 rtems_status_code rtems_rbheap_free(rtems_rbheap_control *control, void *ptr); 00198 00199 static inline rtems_chain_control *rtems_rbheap_get_spare_descriptor_chain( 00200 rtems_rbheap_control *control 00201 ) 00202 { 00203 return &control->spare_descriptor_chain; 00204 } 00205 00206 static inline void rtems_rbheap_add_to_spare_descriptor_chain( 00207 rtems_rbheap_control *control, 00208 rtems_rbheap_chunk *chunk 00209 ) 00210 { 00211 rtems_chain_control *chain = 00212 rtems_rbheap_get_spare_descriptor_chain(control); 00213 00214 rtems_chain_prepend_unprotected(chain, &chunk->chain_node); 00215 } 00216 00217 static inline void rtems_rbheap_set_extend_descriptors( 00218 rtems_rbheap_control *control, 00219 rtems_rbheap_extend_descriptors extend_descriptors 00220 ) 00221 { 00222 control->extend_descriptors = extend_descriptors; 00223 } 00224 00225 static inline void *rtems_rbheap_get_handler_arg( 00226 const rtems_rbheap_control *control 00227 ) 00228 { 00229 return control->handler_arg; 00230 } 00231 00232 static inline void rtems_rbheap_set_handler_arg( 00233 rtems_rbheap_control *control, 00234 void *handler_arg 00235 ) 00236 { 00237 control->handler_arg = handler_arg; 00238 } 00239 00243 void rtems_rbheap_extend_descriptors_never(rtems_rbheap_control *control); 00244 00248 void rtems_rbheap_extend_descriptors_with_malloc( 00249 rtems_rbheap_control *control 00250 ); 00251 00254 /* Private API */ 00255 00256 #define rtems_rbheap_chunk_of_node(node) \ 00257 rtems_rbtree_container_of(node, rtems_rbheap_chunk, tree_node) 00258 00259 static inline bool rtems_rbheap_is_chunk_free(const rtems_rbheap_chunk *chunk) 00260 { 00261 return !rtems_chain_is_node_off_chain(&chunk->chain_node); 00262 } 00263 00264 #ifdef __cplusplus 00265 } 00266 #endif 00267 00268 #endif /* _RTEMS_RBHEAP_H */
1.7.5