source: rtems/cpukit/include/rtems/score/heapimpl.h @ 5803f37

5
Last change on this file since 5803f37 was 4c99921, checked in by Andreas Dachsberger <andreas.dachsberger@…>, on 04/09/19 at 06:50:24

doxygen: score: adjust doc in heapimpl.h to doxygen guidelines

Update #3706.

  • Property mode set to 100644
File size: 22.2 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup RTEMSScoreHeap
5 *
6 * @brief Heap Handler Implementation
7 */
8
9/*
10 *  COPYRIGHT (c) 1989-2008.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.org/license/LICENSE.
16 */
17
18#ifndef _RTEMS_SCORE_HEAPIMPL_H
19#define _RTEMS_SCORE_HEAPIMPL_H
20
21#include <rtems/score/heap.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27/**
28 * @addtogroup RTEMSScoreHeap
29 *
30 * @{
31 */
32
33/**
34 * @brief See also @ref Heap_Block.size_and_flag.
35 */
36#define HEAP_PREV_BLOCK_USED ((uintptr_t) 1)
37
38/**
39 * @brief Size of the part at the block begin which may be used for allocation
40 * in charge of the previous block.
41 */
42#define HEAP_ALLOC_BONUS sizeof(uintptr_t)
43
44/**
45 * @brief See _Heap_Resize_block().
46 */
47typedef enum {
48  HEAP_RESIZE_SUCCESSFUL,
49  HEAP_RESIZE_UNSATISFIED,
50  HEAP_RESIZE_FATAL_ERROR
51} Heap_Resize_status;
52
53/**
54 * @brief Gets the first and last block for the heap area.
55 *
56 * Nothing will be written to this area.
57 *
58 * @param heap_area_begin The starting address of the heap area.
59 * @param heap_area_size The size of the heap area.
60 * @param page_size The page size for the calculation.
61 * @param min_block_size The minimal block size for the calculation.
62 * @param[out] first_block_ptr The pointer to the first block in the case of success
63 * @param[out] last_block_ptr The pointer to the last block in the case of success
64 *
65 * @retval true The area is big enough.
66 * @retval false The area is not big enough.
67 */
68bool _Heap_Get_first_and_last_block(
69  uintptr_t heap_area_begin,
70  uintptr_t heap_area_size,
71  uintptr_t page_size,
72  uintptr_t min_block_size,
73  Heap_Block **first_block_ptr,
74  Heap_Block **last_block_ptr
75);
76
77/**
78 * @brief Initializes the heap control block.
79 *
80 * Blocks of memory are allocated from the heap in multiples of @a page_size
81 * byte units.  If the @a page_size is equal to zero or is not multiple of
82 * @c CPU_ALIGNMENT, it is aligned up to the nearest @c CPU_ALIGNMENT boundary.
83 *
84 * @param[out] heap The heap control block to manage the area.
85 * @param area_begin The starting address of the area.
86 * @param area_size The size of the area in bytes.
87 * @param page_size The page size for the calculation
88 *
89 * @retval some_value The maximum memory available.
90 * @retval 0 The initialization failed.
91 *
92 * @see Heap_Initialization_or_extend_handler.
93 */
94uintptr_t _Heap_Initialize(
95  Heap_Control *heap,
96  void *area_begin,
97  uintptr_t area_size,
98  uintptr_t page_size
99);
100
101/**
102 * @brief Allocates an aligned memory area with boundary constraint.
103 *
104 * A size value of zero will return a unique address which may be freed with
105 * _Heap_Free().
106 *
107 * @param[in, out] heap The heap to allocate a memory are from.
108 * @param size The size of the desired memory are in bytes.
109 * @param alignment The allocated memory area will begin at an address aligned by this value.
110 * @param boundary The allocated memory area will fulfill a boundary constraint,
111 *      if this value is not equal to zero.  The boundary value specifies
112 *      the set of addresses which are aligned by the boundary value.  The
113 *      interior of the allocated memory area will not contain an element of this
114 *      set.  The begin or end address of the area may be a member of the set.
115 *
116 * @retval pointer The starting address of the allocated memory area.
117 * @retval NULL No memory is available of the parameters are inconsistent.
118 */
119void *_Heap_Allocate_aligned_with_boundary(
120  Heap_Control *heap,
121  uintptr_t size,
122  uintptr_t alignment,
123  uintptr_t boundary
124);
125
126/**
127 * @brief Allocates an aligned memory area.
128 *
129 * A size value of zero will return a unique address which may be freed with
130 * _Heap_Free().
131 *
132 * @param[in, out] heap The heap to allocate a memory are from.
133 * @param size The size of the desired memory are in bytes.
134 * @param alignment The allocated memory area will begin at an address aligned by this value.
135 *
136 * @retval pointer The starting address of the allocated memory area.
137 * @retval NULL No memory is available of the parameters are inconsistent.
138 */
139RTEMS_INLINE_ROUTINE void *_Heap_Allocate_aligned(
140  Heap_Control *heap,
141  uintptr_t size,
142  uintptr_t alignment
143)
144{
145  return _Heap_Allocate_aligned_with_boundary( heap, size, alignment, 0 );
146}
147
148/**
149 * @brief Allocates a memory area.
150 *
151 * A size value of zero will return a unique address which may be freed with
152 * _Heap_Free().
153 *
154 * @param[in, out] heap The heap to allocate a memory are from.
155 * @param size The size of the desired memory are in bytes.
156 *
157 * @retval pointer The starting address of the allocated memory area.
158 * @retval NULL No memory is available of the parameters are inconsistent.
159 */
160RTEMS_INLINE_ROUTINE void *_Heap_Allocate( Heap_Control *heap, uintptr_t size )
161{
162  return _Heap_Allocate_aligned_with_boundary( heap, size, 0, 0 );
163}
164
165/**
166 * @brief Frees the allocated memory area.
167 *
168 * Inappropriate values for @a addr may corrupt the heap.
169 *
170 * @param[in, out] heap The heap of the allocated memory area.
171 * @param addr The starting address of the memory area to be freed.
172 *
173 * @retval true The allocated memory area was successfully freed.
174 * @retval false The method failed.
175 */
176bool _Heap_Free( Heap_Control *heap, void *addr );
177
178/**
179 * @brief Verifies the integrity of the heap.
180 *
181 * Walks the heap to verify its integrity.
182 *
183 * @param heap The heap whose integrity is to be verified.
184 * @param source If @a dump is @c true, this is used to mark the output lines.
185 * @param dump Indicates whether diagnostic messages will be printed to standard output.
186 *
187 * @retval true No errors occured, the heapÂŽs integrity is not violated.
188 * @retval false The heap is corrupt.
189 */
190bool _Heap_Walk(
191  Heap_Control *heap,
192  int source,
193  bool dump
194);
195
196/**
197 * @brief Heap block visitor.
198 *
199 * @see _Heap_Iterate().
200 *
201 * @retval true Stop the iteration.
202 * @retval false Continue the iteration.
203 */
204typedef bool (*Heap_Block_visitor)(
205  const Heap_Block *block,
206  uintptr_t block_size,
207  bool block_is_used,
208  void *visitor_arg
209);
210
211/**
212 * @brief Iterates over all blocks of the heap.
213 *
214 * @param[in, out] heap The heap to iterate over.
215 * @param visitor This will be called for each heap block with
216 *      the argument @a visitor_arg.
217 * @param[in, out] visitor_arg The argument for all calls of @a visitor.
218 */
219void _Heap_Iterate(
220  Heap_Control *heap,
221  Heap_Block_visitor visitor,
222  void *visitor_arg
223);
224
225/**
226 * @brief Greedily allocates and empties the heap.
227 *
228 * Afterwards, the heap has at most @a block_count allocatable blocks of sizes
229 * specified by @a block_sizes.  All other blocks are used.
230 *
231 * @param[in, out] heap The heap to operate upon
232 * @param block_sizes The sizes of the allocatable blocks.  Must point to an
233 *      array with @a block_count members.
234 * @param block_count The maximum number of allocatable blocks of sizes
235 *      specified by @block_sizes.
236 *
237 * @return Pointer to the first allocated block.
238 *
239 * @see _Heap_Greedy_free().
240 */
241Heap_Block *_Heap_Greedy_allocate(
242  Heap_Control *heap,
243  const uintptr_t *block_sizes,
244  size_t block_count
245);
246
247/**
248 * @brief Greedily allocates all blocks except the largest free block.
249 *
250 * Afterwards the heap has at most one allocatable block.  This block is the
251 * largest free block if it exists.  All other blocks are used.
252 *
253 * @param[in, out] heap The heap to operate upon.
254 * @param[out] allocatable_size Stores the size of the largest free block of
255 *      the heap after the method call.
256 *
257 * @return Pointer to the first allocated block.
258 *
259 * @see _Heap_Greedy_free().
260 */
261Heap_Block *_Heap_Greedy_allocate_all_except_largest(
262  Heap_Control *heap,
263  uintptr_t *allocatable_size
264);
265
266/**
267 * @brief Frees blocks of a greedy allocation.
268 *
269 * @param[in, out] heap The heap to operate upon.
270 * @param blocks Must be the return value of _Heap_Greedy_allocate().
271 */
272void _Heap_Greedy_free(
273  Heap_Control *heap,
274  Heap_Block *blocks
275);
276
277/**
278 * @brief Returns information about used and free blocks for the heap.
279 *
280 * @param heap The heap to get the information from.
281 * @param[out] info Stores the information of the @a heap after the method call.
282 */
283void _Heap_Get_information(
284  Heap_Control *heap,
285  Heap_Information_block *info
286);
287
288/**
289 * @brief Returns information about free blocks for the heap.
290 *
291 * @param heap The heap to get the information from.
292 * @param[out] info Stores the information about free blocks of @a heap after the
293 *      method call.
294 */
295void _Heap_Get_free_information(
296  Heap_Control *heap,
297  Heap_Information *info
298);
299
300/**
301 * @brief Returns the size of the allocatable memory area.
302 *
303 * The size value may be greater than the initially requested size in
304 * _Heap_Allocate_aligned_with_boundary().
305 *
306 * Inappropriate values for @a addr will not corrupt the heap, but may yield
307 * invalid size values.
308 *
309 * @param heap The heap to operate upon.
310 * @param addr The starting address of the allocatable memory area.
311 * @param[out] size Stores the size of the allocatable memory area after the method call.
312 *
313 * @retval true The operation was successful.
314 * @retval false The operation was not successful.
315 */
316bool _Heap_Size_of_alloc_area(
317  Heap_Control *heap,
318  void *addr,
319  uintptr_t *size
320);
321
322/**
323 * @brief Resizes the block of the allocated memory area.
324 *
325 * Inappropriate values for @a addr may corrupt the heap.
326 *
327 * @param[in, out] heap The heap to operate upon.
328 * @param addr The starting address of the allocated memory area to be resized.
329 * @param size The least possible size for the new memory area.  Resize may be
330 *      impossible and depends on the current heap usage.
331 * @param[out] old_size Stores the size available for allocation in the current
332 *      block before the resize after the method call.
333 * @param[out] new_size Stores the size available for allocation in the resized
334 *      block after the method call.  In the case of an unsuccessful resize,
335 *      zero is returned in this parameter
336 *
337 * @retval HEAP_RESIZE_SUCCESSFUL The resize was successful.
338 * @retval HEAP_RESIZE_UNSATISFIED The least possible size @a size was too big.
339 *      Resize not possible.
340 * @retval HEAP_RESIZE_FATAL_ERROR The block starting at @a addr is not part of
341 *      the heap.
342 */
343Heap_Resize_status _Heap_Resize_block(
344  Heap_Control *heap,
345  void *addr,
346  uintptr_t size,
347  uintptr_t *old_size,
348  uintptr_t *new_size
349);
350
351/**
352 * @brief Allocates the memory area.
353 * starting at @a alloc_begin of size
354 * @a alloc_size bytes in the block @a block.
355 *
356 * The block may be split up into multiple blocks.  The previous and next block
357 * may be used or free.  Free block parts which form a vaild new block will be
358 * inserted into the free list or merged with an adjacent free block.  If the
359 * block is used, they will be inserted after the free list head.  If the block
360 * is free, they will be inserted after the previous block in the free list.
361 *
362 * Inappropriate values for @a alloc_begin or @a alloc_size may corrupt the
363 * heap.
364 *
365 * @param[in, out] heap The heap to operate upon.
366 * @param block The block in which the memory area should be allocated
367 * @param alloc_begin The starting address of the memory area that shall be allocated.
368 * @param alloc_size The size of the desired allocated area in bytes.
369 *
370 * @return The block containing the allocated memory area.
371 */
372Heap_Block *_Heap_Block_allocate(
373  Heap_Control *heap,
374  Heap_Block *block,
375  uintptr_t alloc_begin,
376  uintptr_t alloc_size
377);
378
379#ifndef HEAP_PROTECTION
380  #define _Heap_Protection_block_initialize( heap, block ) ((void) 0)
381  #define _Heap_Protection_block_check( heap, block ) ((void) 0)
382  #define _Heap_Protection_block_error( heap, block ) ((void) 0)
383  #define _Heap_Protection_free_all_delayed_blocks( heap ) ((void) 0)
384#else
385  static inline void _Heap_Protection_block_initialize(
386    Heap_Control *heap,
387    Heap_Block *block
388  )
389  {
390    (*heap->Protection.block_initialize)( heap, block );
391  }
392
393  static inline void _Heap_Protection_block_check(
394    Heap_Control *heap,
395    Heap_Block *block
396  )
397  {
398    (*heap->Protection.block_check)( heap, block );
399  }
400
401  static inline void _Heap_Protection_block_error(
402    Heap_Control *heap,
403    Heap_Block *block
404  )
405  {
406    (*heap->Protection.block_error)( heap, block );
407  }
408
409  static inline void _Heap_Protection_free_all_delayed_blocks( Heap_Control *heap )
410  {
411    uintptr_t large = 0
412      - (uintptr_t) HEAP_BLOCK_HEADER_SIZE
413      - (uintptr_t) HEAP_ALLOC_BONUS
414      - (uintptr_t) 1;
415    void *p = _Heap_Allocate( heap, large );
416    _Heap_Free( heap, p );
417  }
418#endif
419
420/**
421 * @brief Sets the fraction of delayed free blocks that is actually freed
422 * during memory shortage.
423 *
424 * The default is to free half the delayed free blocks.  This is equal to a
425 * fraction value of two.
426 *
427 * @param[in, out] heap The heap control.
428 * @param fraction The fraction is one divided by this fraction value.
429 */
430RTEMS_INLINE_ROUTINE void _Heap_Protection_set_delayed_free_fraction(
431  Heap_Control *heap,
432  uintptr_t fraction
433)
434{
435#ifdef HEAP_PROTECTION
436  heap->Protection.delayed_free_fraction = fraction;
437#else
438  (void) heap;
439  (void) fraction;
440#endif
441}
442
443/**
444 * @brief Returns the head of the free list of the heap.
445 *
446 * @param heap The heap to operate upon.
447 *
448 * @return The head of the free list.
449 */
450RTEMS_INLINE_ROUTINE Heap_Block *_Heap_Free_list_head( Heap_Control *heap )
451{
452  return &heap->free_list;
453}
454
455/**
456 * @brief Returns the tail of the free list of the heap.
457 *
458 * @param heap The heap to operate upon.
459 *
460 * @return The tail of the free list.
461 */
462RTEMS_INLINE_ROUTINE Heap_Block *_Heap_Free_list_tail( Heap_Control *heap )
463{
464  return &heap->free_list;
465}
466
467/**
468 * @brief Returns the first block of the free list of the heap.
469 *
470 * @param heap The heap to operate upon.
471 *
472 * @return The first block of the free list.
473 */
474RTEMS_INLINE_ROUTINE Heap_Block *_Heap_Free_list_first( Heap_Control *heap )
475{
476  return _Heap_Free_list_head(heap)->next;
477}
478
479/**
480 * @brief Returns the last block of the free list of the heap.
481 *
482 * @param heap The heap to operate upon.
483 *
484 * @return The last block of the free list.
485 */
486RTEMS_INLINE_ROUTINE Heap_Block *_Heap_Free_list_last( Heap_Control *heap )
487{
488  return _Heap_Free_list_tail(heap)->prev;
489}
490
491/**
492 * @brief Removes the block from the free list.
493 *
494 * @param block The block to be removed.
495 */
496RTEMS_INLINE_ROUTINE void _Heap_Free_list_remove( Heap_Block *block )
497{
498  Heap_Block *next = block->next;
499  Heap_Block *prev = block->prev;
500
501  prev->next = next;
502  next->prev = prev;
503}
504
505/**
506 * @brief Replaces one block in the free list by another.
507 *
508 * @param old_block The block in the free list to replace.
509 * @param new_block The block that should replace @a old_block.
510 */
511RTEMS_INLINE_ROUTINE void _Heap_Free_list_replace(
512  Heap_Block *old_block,
513  Heap_Block *new_block
514)
515{
516  Heap_Block *next = old_block->next;
517  Heap_Block *prev = old_block->prev;
518
519  new_block->next = next;
520  new_block->prev = prev;
521
522  next->prev = new_block;
523  prev->next = new_block;
524}
525
526/**
527 * @brief Inserts a block after an existing block in the free list.
528 *
529 * @param block_before The block that is already in the free list.
530 * @param new_block The block to be inserted after @a block_before.
531 */
532RTEMS_INLINE_ROUTINE void _Heap_Free_list_insert_after(
533  Heap_Block *block_before,
534  Heap_Block *new_block
535)
536{
537  Heap_Block *next = block_before->next;
538
539  new_block->next = next;
540  new_block->prev = block_before;
541  block_before->next = new_block;
542  next->prev = new_block;
543}
544
545/**
546 * @brief Inserts a block before an existing block in the free list.
547 *
548 * @param block_before The block that is already in the free list.
549 * @param new_block The block to be inserted before @a block_before.
550 */
551RTEMS_INLINE_ROUTINE void _Heap_Free_list_insert_before(
552  Heap_Block *block_next,
553  Heap_Block *new_block
554)
555{
556  Heap_Block *prev = block_next->prev;
557
558  new_block->next = block_next;
559  new_block->prev = prev;
560  prev->next = new_block;
561  block_next->prev = new_block;
562}
563
564/**
565 * @brief Checks if the value is aligned to the given alignment.
566 *
567 * @param value The value to check the alignment of.
568 * @param alignment The alignment for the operation.
569 *
570 * @retval true The value is aligned to the given alignment.
571 * @retval false The value is not aligned to the given alignment.
572 */
573RTEMS_INLINE_ROUTINE bool _Heap_Is_aligned(
574  uintptr_t value,
575  uintptr_t alignment
576)
577{
578  return (value % alignment) == 0;
579}
580
581/**
582 * @brief Returns the aligned value, truncating.
583 *
584 * @param value The value to be aligned
585 * @param alignment The alignment for the operation.
586 *
587 * @return The aligned value, truncated.
588 */
589RTEMS_INLINE_ROUTINE uintptr_t _Heap_Align_down(
590  uintptr_t value,
591  uintptr_t alignment
592)
593{
594  return value - (value % alignment);
595}
596
597/**
598 * @brief Returns the block which is @a offset away from @a block.
599 *
600 * @param block The block for the relative calculation.
601 * @param offset The offset for the calculation.
602 *
603 * @return The address of the block which is @a offset away from @a block.
604 */
605RTEMS_INLINE_ROUTINE Heap_Block *_Heap_Block_at(
606  const Heap_Block *block,
607  uintptr_t offset
608)
609{
610  return (Heap_Block *) ((uintptr_t) block + offset);
611}
612
613/**
614 * @brief Returns the address of the previous block.
615 *
616 * @param block The block of which the address of the previous block is requested.
617 *
618 * @return The address of the previous block.
619 */
620RTEMS_INLINE_ROUTINE Heap_Block *_Heap_Prev_block(
621  const Heap_Block *block
622)
623{
624  return (Heap_Block *) ((uintptr_t) block - block->prev_size);
625}
626
627/**
628 * @brief Returns the first address in the block without the heap header.
629 *
630 * @param block The block for the operation.
631 *
632 * @return The first address after the heap header.
633 */
634RTEMS_INLINE_ROUTINE uintptr_t _Heap_Alloc_area_of_block(
635  const Heap_Block *block
636)
637{
638  return (uintptr_t) block + HEAP_BLOCK_HEADER_SIZE;
639}
640
641/**
642 * @brief Returns the starting address of the block corresponding to the allocatable area.
643 *
644 * @param alloc_begin The starting address of the allocatable area.
645 * @param page_size The page size for the calculation.
646 *
647 * @return The Starting address of the corresponding block of the allocatable area.
648 */
649RTEMS_INLINE_ROUTINE Heap_Block *_Heap_Block_of_alloc_area(
650  uintptr_t alloc_begin,
651  uintptr_t page_size
652)
653{
654  return (Heap_Block *) (_Heap_Align_down( alloc_begin, page_size )
655    - HEAP_BLOCK_HEADER_SIZE);
656}
657
658/**
659 * @brief Returns the block size.
660 *
661 * @param block The block of which the size is requested.
662 *
663 * @return The block size.
664 */
665RTEMS_INLINE_ROUTINE uintptr_t _Heap_Block_size( const Heap_Block *block )
666{
667  return block->size_and_flag & ~HEAP_PREV_BLOCK_USED;
668}
669
670/**
671 * @brief Sets the block size.
672 *
673 * @param[in, out] block The block of which the size shall be set.
674 * @param size The new size of the block.
675 */
676RTEMS_INLINE_ROUTINE void _Heap_Block_set_size(
677  Heap_Block *block,
678  uintptr_t size
679)
680{
681  uintptr_t flag = block->size_and_flag & HEAP_PREV_BLOCK_USED;
682
683  block->size_and_flag = size | flag;
684}
685
686/**
687 * @brief Returns if the previous heap block is used.
688 *
689 * @param block The block of which the information about the previous
690 *      block is requested.
691 *
692 * @retval true The previous block is used.
693 * @retval false The previous block is not used.
694 */
695RTEMS_INLINE_ROUTINE bool _Heap_Is_prev_used( const Heap_Block *block )
696{
697  return block->size_and_flag & HEAP_PREV_BLOCK_USED;
698}
699
700/**
701 * @brief Returns if the heap block is used.
702 *
703 * @param block The block of which the information is requested.
704 *
705 * @retval true The block is used.
706 * @retval false The block is not used.
707 */
708RTEMS_INLINE_ROUTINE bool _Heap_Is_used(
709  const Heap_Block *block
710)
711{
712  const Heap_Block *const next_block =
713    _Heap_Block_at( block, _Heap_Block_size( block ) );
714
715  return _Heap_Is_prev_used( next_block );
716}
717
718/**
719 * @brief Returns if the heap block is free.
720 *
721 * @param block The block of which the information is requested.
722 *
723 * @retval true The block is free.
724 * @retval false The block is not free.
725 */
726RTEMS_INLINE_ROUTINE bool _Heap_Is_free(
727  const Heap_Block *block
728)
729{
730  return !_Heap_Is_used( block );
731}
732
733/**
734 * @brief Returns if the block is part of the heap.
735 *
736 * @param heap The heap to test if the @a block is part of it.
737 * @param block The block of which the information is requested.
738 *
739 * @retval true The block is part of the heap.
740 * @retval false The block is not part of the heap.
741 */
742RTEMS_INLINE_ROUTINE bool _Heap_Is_block_in_heap(
743  const Heap_Control *heap,
744  const Heap_Block *block
745)
746{
747  return (uintptr_t) block >= (uintptr_t) heap->first_block
748    && (uintptr_t) block <= (uintptr_t) heap->last_block;
749}
750
751/**
752 * @brief Sets the size of the last block for the heap.
753 *
754 * The next block of the last block will be the first block.  Since the first
755 * block indicates that the previous block is used, this ensures that the last
756 * block appears as used for the _Heap_Is_used() and _Heap_Is_free()
757 * functions.
758 *
759 * This feature will be used to terminate the scattered heap area list.  See
760 * also _Heap_Extend().
761 *
762 * @param[in, out] heap The heap to set the last block size of.
763 */
764RTEMS_INLINE_ROUTINE void _Heap_Set_last_block_size( Heap_Control *heap )
765{
766  _Heap_Block_set_size(
767    heap->last_block,
768    (uintptr_t) heap->first_block - (uintptr_t) heap->last_block
769  );
770}
771
772/**
773 * @brief Returns the size of the allocatable area in bytes.
774 *
775 * This value is an integral multiple of the page size.
776 *
777 * @param heap The heap to get the allocatable area from.
778 *
779 * @return The size of the allocatable area in @a heap in bytes.
780 */
781RTEMS_INLINE_ROUTINE uintptr_t _Heap_Get_size( const Heap_Control *heap )
782{
783  return heap->stats.size;
784}
785
786/**
787 * @brief Returns the bigger one of the two arguments.
788 *
789 * @param a The parameter on the left hand side of the comparison.
790 * @param b The parameter on the right hand side of the comparison.
791 *
792 * @retval a If a > b.
793 * @retval b If b >= a
794 */
795RTEMS_INLINE_ROUTINE uintptr_t _Heap_Max( uintptr_t a, uintptr_t b )
796{
797  return a > b ? a : b;
798}
799
800/**
801 * @brief Returns the smaller one of the two arguments.
802 *
803 * @param a The parameter on the left hand side of the comparison.
804 * @param b The parameter on the right hand side of the comparison.
805 *
806 * @retval a If a < b.
807 * @retval b If b <= a
808 */
809RTEMS_INLINE_ROUTINE uintptr_t _Heap_Min( uintptr_t a, uintptr_t b )
810{
811  return a < b ? a : b;
812}
813
814#ifdef RTEMS_DEBUG
815  #define RTEMS_HEAP_DEBUG
816#endif
817
818#ifdef RTEMS_HEAP_DEBUG
819  #include <assert.h>
820  #define _HAssert( cond ) \
821    do { \
822      if ( !(cond) ) { \
823        __assert( __FILE__, __LINE__, #cond ); \
824      } \
825    } while (0)
826#else
827  #define _HAssert( cond ) ((void) 0)
828#endif
829
830/** @} */
831
832#ifdef __cplusplus
833}
834#endif
835
836#endif
837/* end of include file */
Note: See TracBrowser for help on using the repository browser.