summaryrefslogblamecommitdiffstats
path: root/cpukit/score/macros/rtems/score/heap.inl
blob: 47df0551006e38ff8d13d4857a0a980ead42f5ff (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13












                                                                          
        




                  
                                

























                                                   
       










                                                    
       












                                                          











                                                                  

































































                                                    
/*  heap.inl
 *
 *  This file contains the macro implementation of the inlined
 *  routines from the heap handler.
 *
 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
 *  On-Line Applications Research Corporation (OAR).
 *  All rights assigned to U.S. Government, 1994.
 *
 *  This material may be reproduced by or for the U.S. Government pursuant
 *  to the copyright license under the clause at DFARS 252.227-7013.  This
 *  notice must appear in all copies of this file and its derivatives.
 *
 *  $Id$
 */

#ifndef __HEAP_inl
#define __HEAP_inl

#include <rtems/score/address.h>

/*PAGE
 *
 *  _Heap_Head
 */

#define _Heap_Head( _the_heap ) \
  ((Heap_Block *)&(_the_heap)->start)

/*PAGE
 *
 *  _Heap_Tail
 */

#define _Heap_Tail( _the_heap ) \
  ((Heap_Block *)&(_the_heap)->final)

/*PAGE
 *
 *  _Heap_Previous_block
 */

#define _Heap_Previous_block( _the_block ) \
  ( (Heap_Block *) _Addresses_Subtract_offset( \
      (void *)(_the_block), \
      (_the_block)->back_flag & ~ HEAP_BLOCK_USED \
    ) \
  )

/*PAGE
 *
 *  _Heap_Next_block
 */

#define _Heap_Next_block( _the_block ) \
  ( (Heap_Block *) _Addresses_Add_offset( \
      (void *)(_the_block), \
      (_the_block)->front_flag & ~ HEAP_BLOCK_USED \
    ) \
  )

/*PAGE
 *
 *  _Heap_Block_at
 */

#define _Heap_Block_at( _base, _offset ) \
  ( (Heap_Block *) \
     _Addresses_Add_offset( (void *)(_base), (_offset) ) )

/*PAGE
 *
 *  _Heap_User_Block_at
 *
 */
 
#define _Heap_User_Block_at( _base ) \
  _Heap_Block_at( \
    (_base), \
    -*(((unsigned32 *) (_base)) - 1) + -HEAP_BLOCK_USED_OVERHEAD \
  )

/*PAGE
 *
 *  _Heap_Is_previous_block_free
 */

#define _Heap_Is_previous_block_free( _the_block ) \
  ( !((_the_block)->back_flag & HEAP_BLOCK_USED) )

/*PAGE
 *
 *  _Heap_Is_block_free
 */

#define _Heap_Is_block_free( _the_block ) \
  ( !((_the_block)->front_flag & HEAP_BLOCK_USED) )

/*PAGE
 *
 *  _Heap_Is_block_used
 */

#define _Heap_Is_block_used( _the_block ) \
  ((_the_block)->front_flag & HEAP_BLOCK_USED)

/*PAGE
 *
 *  _Heap_Block_size
 */

#define _Heap_Block_size( _the_block )    \
  ((_the_block)->front_flag & ~HEAP_BLOCK_USED)

/*PAGE
 *
 *  _Heap_Start_of_user_area
 */

#define _Heap_Start_of_user_area( _the_block ) \
  ((void *) &(_the_block)->next)

/*PAGE
 *
 *  _Heap_Is_block_in
 */

#define _Heap_Is_block_in( _the_heap, _the_block ) \
  ( ((_the_block) >= (_the_heap)->start) && \
    ((_the_block) <= (_the_heap)->final) )

/*PAGE
 *
 *  _Heap_Is_page_size_valid
 */

#define _Heap_Is_page_size_valid( _page_size ) \
  ( ((_page_size) != 0) && \
    (((_page_size) % CPU_HEAP_ALIGNMENT) == 0) )

/*PAGE
 *
 *  _Heap_Build_flag
 */

#define _Heap_Build_flag( _size, _in_use_flag ) \
  ( (_size) | (_in_use_flag))

#endif
/* end of include file */