Changeset e6f7f81 in rtems for cpukit/score


Ignore:
Timestamp:
Jul 23, 2013, 2:50:51 PM (6 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
f41eeb0
Parents:
7121a9fa
git-author:
Sebastian Huber <sebastian.huber@…> (07/23/13 14:50:51)
git-committer:
Sebastian Huber <sebastian.huber@…> (07/23/13 15:19:08)
Message:

score: Create heap implementation header

Move implementation specific parts of heap.h and heap.inl into new
header file heapimpl.h. The heap.h contains now only the application
visible API.

Location:
cpukit/score
Files:
1 added
1 deleted
17 edited

Legend:

Unmodified
Added
Removed
  • cpukit/score/Makefile.am

    r7121a9fa re6f7f81  
    3232include_rtems_score_HEADERS += include/rtems/score/coresemimpl.h
    3333include_rtems_score_HEADERS += include/rtems/score/heap.h
     34include_rtems_score_HEADERS += include/rtems/score/heapimpl.h
    3435include_rtems_score_HEADERS += include/rtems/score/protectedheap.h
    3536include_rtems_score_HEADERS += include/rtems/score/interr.h
     
    9394
    9495## inline
    95 include_rtems_score_HEADERS += inline/rtems/score/heap.inl
    9696include_rtems_score_HEADERS += inline/rtems/score/object.inl
    9797include_rtems_score_HEADERS += inline/rtems/score/priority.inl
  • cpukit/score/include/rtems/score/heap.h

    r7121a9fa re6f7f81  
    1919#define _RTEMS_SCORE_HEAP_H
    2020
    21 #include <rtems/system.h>
    22 #include <rtems/score/thread.h>
     21#include <rtems/score/basedefs.h>
    2322
    2423#ifdef __cplusplus
     
    137136  #define HEAP_PROTECTION_HEADER_SIZE 0
    138137#else
     138  #include <rtems/score/thread.h>
     139
    139140  #define HEAP_PROTECTOR_COUNT 2
    140141
     
    177178    (sizeof(Heap_Protection_block_begin) + sizeof(Heap_Protection_block_end))
    178179#endif
    179 
    180 /**
    181  * @brief See also @ref Heap_Block.size_and_flag.
    182  */
    183 #define HEAP_PREV_BLOCK_USED ((uintptr_t) 1)
    184 
    185 /**
    186  * @brief Size of the part at the block begin which may be used for allocation
    187  * in charge of the previous block.
    188  */
    189 #define HEAP_ALLOC_BONUS sizeof(uintptr_t)
    190180
    191181/**
     
    379369
    380370/**
    381  * @brief See _Heap_Resize_block().
    382  */
    383 typedef enum {
    384   HEAP_RESIZE_SUCCESSFUL,
    385   HEAP_RESIZE_UNSATISFIED,
    386   HEAP_RESIZE_FATAL_ERROR
    387 } Heap_Resize_status;
    388 
    389 /**
    390371 * @brief Heap area structure for table based heap initialization and
    391372 * extension.
     
    415396
    416397/**
    417  * @brief Gets the first and last block for the heap area with begin
    418  * @a heap_area_begin and size @a heap_area_size.
    419  *
    420  * A page size of @a page_size and minimal block size of @a min_block_size will
    421  * be used for calculation.
    422  *
    423  * Nothing will be written to this area.
    424  *
    425  * In case of success the pointers to the first and last block will be returned
    426  * via @a first_block_ptr and @a last_block_ptr.
    427  *
    428  * Returns @c true if the area is big enough, and @c false otherwise.
    429  */
    430 bool _Heap_Get_first_and_last_block(
    431   uintptr_t heap_area_begin,
    432   uintptr_t heap_area_size,
    433   uintptr_t page_size,
    434   uintptr_t min_block_size,
    435   Heap_Block **first_block_ptr,
    436   Heap_Block **last_block_ptr
    437 );
    438 
    439 /**
    440  * @brief Initializes the heap control block @a heap to manage the area
    441  * starting at @a area_begin of size @a area_size bytes.
    442  *
    443  * Blocks of memory are allocated from the heap in multiples of @a page_size
    444  * byte units.  If the @a page_size is equal to zero or is not multiple of
    445  * @c CPU_ALIGNMENT, it is aligned up to the nearest @c CPU_ALIGNMENT boundary.
    446  *
    447  * Returns the maximum memory available, or zero in case of failure.
    448  *
    449  * @see Heap_Initialization_or_extend_handler.
    450  */
    451 uintptr_t _Heap_Initialize(
    452   Heap_Control *heap,
    453   void *area_begin,
    454   uintptr_t area_size,
    455   uintptr_t page_size
    456 );
    457 
    458 /**
    459398 * @brief Extends the memory available for the heap @a heap using the memory
    460399 * area starting at @a area_begin of size @a area_size bytes.
     
    496435);
    497436
    498 /**
    499  * @brief Allocates a memory area of size @a size bytes from the heap @a heap.
    500  *
    501  * If the alignment parameter @a alignment is not equal to zero, the allocated
    502  * memory area will begin at an address aligned by this value.
    503  *
    504  * If the boundary parameter @a boundary is not equal to zero, the allocated
    505  * memory area will fulfill a boundary constraint.  The boundary value
    506  * specifies the set of addresses which are aligned by the boundary value.  The
    507  * interior of the allocated memory area will not contain an element of this
    508  * set.  The begin or end address of the area may be a member of the set.
    509  *
    510  * A size value of zero will return a unique address which may be freed with
    511  * _Heap_Free().
    512  *
    513  * Returns a pointer to the begin of the allocated memory area, or @c NULL if
    514  * no memory is available or the parameters are inconsistent.
    515  */
    516 void *_Heap_Allocate_aligned_with_boundary(
    517   Heap_Control *heap,
    518   uintptr_t size,
    519   uintptr_t alignment,
    520   uintptr_t boundary
    521 );
    522 
    523 /**
    524  * @brief See _Heap_Allocate_aligned_with_boundary() with boundary equals zero.
    525  */
    526 RTEMS_INLINE_ROUTINE void *_Heap_Allocate_aligned(
    527   Heap_Control *heap,
    528   uintptr_t size,
    529   uintptr_t alignment
    530 )
    531 {
    532   return _Heap_Allocate_aligned_with_boundary( heap, size, alignment, 0 );
    533 }
    534 
    535 /**
    536  * @brief See _Heap_Allocate_aligned_with_boundary() with alignment and
    537  * boundary equals zero.
    538  */
    539 RTEMS_INLINE_ROUTINE void *_Heap_Allocate( Heap_Control *heap, uintptr_t size )
    540 {
    541   return _Heap_Allocate_aligned_with_boundary( heap, size, 0, 0 );
    542 }
    543 
    544 /**
    545  * @brief Frees the allocated memory area starting at @a addr in the heap
    546  * @a heap.
    547  *
    548  * Inappropriate values for @a addr may corrupt the heap.
    549  *
    550  * Returns @c true in case of success, and @c false otherwise.
    551  */
    552 bool _Heap_Free( Heap_Control *heap, void *addr );
    553 
    554 /**
    555  * @brief Walks the heap @a heap to verify its integrity.
    556  *
    557  * If @a dump is @c true, then diagnostic messages will be printed to standard
    558  * output.  In this case @a source is used to mark the output lines.
    559  *
    560  * Returns @c true if no errors occurred, and @c false if the heap is corrupt.
    561  */
    562 bool _Heap_Walk(
    563   Heap_Control *heap,
    564   int source,
    565   bool dump
    566 );
    567 
    568 /**
    569  * @brief Heap block visitor.
    570  *
    571  * @see _Heap_Iterate().
    572  *
    573  * @retval true Stop the iteration.
    574  * @retval false Continue the iteration.
    575  */
    576 typedef bool (*Heap_Block_visitor)(
    577   const Heap_Block *block,
    578   uintptr_t block_size,
    579   bool block_is_used,
    580   void *visitor_arg
    581 );
    582 
    583 /**
    584  * @brief Iterates over all blocks of the heap.
    585  *
    586  * For each block the @a visitor with the argument @a visitor_arg will be
    587  * called.
    588  */
    589 void _Heap_Iterate(
    590   Heap_Control *heap,
    591   Heap_Block_visitor visitor,
    592   void *visitor_arg
    593 );
    594 
    595 /**
    596  * @brief Greedy allocate that empties the heap.
    597  *
    598  * Afterwards the heap has at most @a block_count allocatable blocks of sizes
    599  * specified by @a block_sizes.  The @a block_sizes must point to an array with
    600  * @a block_count members.  All other blocks are used.
    601  *
    602  * @see _Heap_Greedy_free().
    603  */
    604 Heap_Block *_Heap_Greedy_allocate(
    605   Heap_Control *heap,
    606   const uintptr_t *block_sizes,
    607   size_t block_count
    608 );
    609 
    610 /**
    611  * @brief Greedy allocate all blocks except the largest free block.
    612  *
    613  * Afterwards the heap has at most one allocatable block.  This block is the
    614  * largest free block if it exists.  The allocatable size of this block is
    615  * stored in @a allocatable_size.  All other blocks are used.
    616  *
    617  * @see _Heap_Greedy_free().
    618  */
    619 Heap_Block *_Heap_Greedy_allocate_all_except_largest(
    620   Heap_Control *heap,
    621   uintptr_t *allocatable_size
    622 );
    623 
    624 /**
    625  * @brief Frees blocks of a greedy allocation.
    626  *
    627  * The @a blocks must be the return value of _Heap_Greedy_allocate().
    628  */
    629 void _Heap_Greedy_free(
    630   Heap_Control *heap,
    631   Heap_Block *blocks
    632 );
    633 
    634 /**
    635  * @brief Returns information about used and free blocks for the heap @a heap
    636  * in @a info.
    637  */
    638 void _Heap_Get_information(
    639   Heap_Control *heap,
    640   Heap_Information_block *info
    641 );
    642 
    643 /**
    644  * @brief Returns information about free blocks for the heap @a heap in
    645  * @a info.
    646  */
    647 void _Heap_Get_free_information(
    648   Heap_Control *heap,
    649   Heap_Information *info
    650 );
    651 
    652 /**
    653  * @brief Returns the size of the allocatable memory area starting at @a addr
    654  * in @a size.
    655  *
    656  * The size value may be greater than the initially requested size in
    657  * _Heap_Allocate_aligned_with_boundary().
    658  *
    659  * Inappropriate values for @a addr will not corrupt the heap, but may yield
    660  * invalid size values.
    661  *
    662  * Returns @a true if successful, and @c false otherwise.
    663  */
    664 bool _Heap_Size_of_alloc_area(
    665   Heap_Control *heap,
    666   void *addr,
    667   uintptr_t *size
    668 );
    669 
    670 /**
    671  * @brief Resizes the block of the allocated memory area starting at @a addr.
    672  *
    673  * The new memory area will have a size of at least @a size bytes.  A resize
    674  * may be impossible and depends on the current heap usage.
    675  *
    676  * The size available for allocation in the current block before the resize
    677  * will be returned in @a old_size.  The size available for allocation in
    678  * the resized block will be returned in @a new_size.  If the resize was not
    679  * successful, then a value of zero will be returned in @a new_size.
    680  *
    681  * Inappropriate values for @a addr may corrupt the heap.
    682  */
    683 Heap_Resize_status _Heap_Resize_block(
    684   Heap_Control *heap,
    685   void *addr,
    686   uintptr_t size,
    687   uintptr_t *old_size,
    688   uintptr_t *new_size
    689 );
    690 
    691 RTEMS_INLINE_ROUTINE uintptr_t _Heap_Align_up(
    692   uintptr_t value,
    693   uintptr_t alignment
    694 )
    695 {
    696   uintptr_t remainder = value % alignment;
    697 
    698   if ( remainder != 0 ) {
    699     return value - remainder + alignment;
    700   } else {
    701     return value;
    702   }
    703 }
    704 
    705 /**
    706  * @brief Returns the worst case overhead to manage a memory area.
    707  */
    708 RTEMS_INLINE_ROUTINE uintptr_t _Heap_Area_overhead(
    709   uintptr_t page_size
    710 )
    711 {
    712   if ( page_size != 0 ) {
    713     page_size = _Heap_Align_up( page_size, CPU_ALIGNMENT );
    714   } else {
    715     page_size = CPU_ALIGNMENT;
    716   }
    717 
    718   return 2 * (page_size - 1) + HEAP_BLOCK_HEADER_SIZE;
    719 }
    720 
    721 #if !defined(__RTEMS_APPLICATION__)
    722 
    723 #include <rtems/score/heap.inl>
    724 
    725 /**
    726  * @brief Allocates the memory area starting at @a alloc_begin of size
    727  * @a alloc_size bytes in the block @a block.
    728  *
    729  * The block may be split up into multiple blocks.  The previous and next block
    730  * may be used or free.  Free block parts which form a vaild new block will be
    731  * inserted into the free list or merged with an adjacent free block.  If the
    732  * block is used, they will be inserted after the free list head.  If the block
    733  * is free, they will be inserted after the previous block in the free list.
    734  *
    735  * Inappropriate values for @a alloc_begin or @a alloc_size may corrupt the
    736  * heap.
    737  *
    738  * Returns the block containing the allocated memory area.
    739  */
    740 Heap_Block *_Heap_Block_allocate(
    741   Heap_Control *heap,
    742   Heap_Block *block,
    743   uintptr_t alloc_begin,
    744   uintptr_t alloc_size
    745 );
    746 
    747 #ifndef HEAP_PROTECTION
    748   #define _Heap_Protection_block_initialize( heap, block ) ((void) 0)
    749   #define _Heap_Protection_block_check( heap, block ) ((void) 0)
    750   #define _Heap_Protection_block_error( heap, block ) ((void) 0)
    751   #define _Heap_Protection_free_all_delayed_blocks( heap ) ((void) 0)
    752 #else
    753   static inline void _Heap_Protection_block_initialize(
    754     Heap_Control *heap,
    755     Heap_Block *block
    756   )
    757   {
    758     (*heap->Protection.block_initialize)( heap, block );
    759   }
    760 
    761   static inline void _Heap_Protection_block_check(
    762     Heap_Control *heap,
    763     Heap_Block *block
    764   )
    765   {
    766     (*heap->Protection.block_check)( heap, block );
    767   }
    768 
    769   static inline void _Heap_Protection_block_error(
    770     Heap_Control *heap,
    771     Heap_Block *block
    772   )
    773   {
    774     (*heap->Protection.block_error)( heap, block );
    775   }
    776 
    777   static inline void _Heap_Protection_free_all_delayed_blocks( Heap_Control *heap )
    778   {
    779     uintptr_t large = 0
    780       - (uintptr_t) HEAP_BLOCK_HEADER_SIZE
    781       - (uintptr_t) HEAP_ALLOC_BONUS
    782       - (uintptr_t) 1;
    783     void *p = _Heap_Allocate( heap, large );
    784     _Heap_Free( heap, p );
    785   }
    786 #endif
    787 
    788437/** @} */
    789 
    790 #ifdef RTEMS_DEBUG
    791   #define RTEMS_HEAP_DEBUG
    792 #endif
    793 
    794 #ifdef RTEMS_HEAP_DEBUG
    795   #include <assert.h>
    796   #define _HAssert( cond ) \
    797     do { \
    798       if ( !(cond) ) { \
    799         __assert( __FILE__, __LINE__, #cond ); \
    800       } \
    801     } while (0)
    802 #else
    803   #define _HAssert( cond ) ((void) 0)
    804 #endif
    805 
    806 #endif /* !defined(__RTEMS_APPLICATION__) */
    807438
    808439#ifdef __cplusplus
  • cpukit/score/include/rtems/score/protectedheap.h

    r7121a9fa re6f7f81  
    1919#define _RTEMS_SCORE_PROTECTED_HEAP_H
    2020
    21 #include <rtems/score/heap.h>
     21#include <rtems/score/heapimpl.h>
    2222#include <rtems/score/apimutex.h>
    2323
  • cpukit/score/preinstall.am

    r7121a9fa re6f7f81  
    108108PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/heap.h
    109109
     110$(PROJECT_INCLUDE)/rtems/score/heapimpl.h: include/rtems/score/heapimpl.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
     111        $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/heapimpl.h
     112PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/heapimpl.h
     113
    110114$(PROJECT_INCLUDE)/rtems/score/protectedheap.h: include/rtems/score/protectedheap.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
    111115        $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/protectedheap.h
     
    300304PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/schedulersimplesmp.h
    301305endif
    302 $(PROJECT_INCLUDE)/rtems/score/heap.inl: inline/rtems/score/heap.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
    303         $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/heap.inl
    304 PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/heap.inl
    305 
    306306$(PROJECT_INCLUDE)/rtems/score/object.inl: inline/rtems/score/object.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
    307307        $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/object.inl
  • cpukit/score/src/heap.c

    r7121a9fa re6f7f81  
    1919
    2020#if HAVE_CONFIG_H
    21 #include "config.h"
     21  #include "config.h"
    2222#endif
    2323
     24#include <rtems/score/heapimpl.h>
     25#include <rtems/score/interr.h>
     26
    2427#include <string.h>
    25 
    26 #include <rtems/system.h>
    27 #include <rtems/score/heap.h>
    28 #include <rtems/score/interr.h>
    2928
    3029#if CPU_ALIGNMENT == 0 || CPU_ALIGNMENT % 2 != 0
  • cpukit/score/src/heapallocate.c

    r7121a9fa re6f7f81  
    2424#include <rtems/system.h>
    2525#include <rtems/score/sysstate.h>
    26 #include <rtems/score/heap.h>
     26#include <rtems/score/heapimpl.h>
    2727
    2828#ifndef HEAP_PROTECTION
  • cpukit/score/src/heapextend.c

    r7121a9fa re6f7f81  
    2424#include <rtems/system.h>
    2525#include <rtems/score/sysstate.h>
    26 #include <rtems/score/heap.h>
     26#include <rtems/score/heapimpl.h>
    2727
    2828static void _Heap_Free_block( Heap_Control *heap, Heap_Block *block )
  • cpukit/score/src/heapfree.c

    r7121a9fa re6f7f81  
    2121
    2222#include <rtems/system.h>
    23 #include <rtems/score/heap.h>
     23#include <rtems/score/heapimpl.h>
    2424
    2525#ifndef HEAP_PROTECTION
  • cpukit/score/src/heapgetfreeinfo.c

    r7121a9fa re6f7f81  
    2222#include <rtems/system.h>
    2323#include <rtems/score/sysstate.h>
    24 #include <rtems/score/heap.h>
     24#include <rtems/score/heapimpl.h>
    2525
    2626void _Heap_Get_free_information(
  • cpukit/score/src/heapgetinfo.c

    r7121a9fa re6f7f81  
    2222#include <string.h>
    2323
    24 #include <rtems/score/heap.h>
     24#include <rtems/score/heapimpl.h>
    2525
    2626static bool _Heap_Get_information_visitor(
  • cpukit/score/src/heapgreedy.c

    r7121a9fa re6f7f81  
    2525#endif
    2626
    27 #include <rtems/score/heap.h>
     27#include <rtems/score/heapimpl.h>
    2828
    2929Heap_Block *_Heap_Greedy_allocate(
  • cpukit/score/src/heapiterate.c

    r7121a9fa re6f7f81  
    2525#endif
    2626
    27 #include <rtems/score/heap.h>
     27#include <rtems/score/heapimpl.h>
    2828
    2929void _Heap_Iterate(
  • cpukit/score/src/heapnoextend.c

    r7121a9fa re6f7f81  
    2525#endif
    2626
    27 #include <rtems/score/heap.h>
     27#include <rtems/score/heapimpl.h>
    2828
    2929uintptr_t _Heap_No_extend(
  • cpukit/score/src/heapresizeblock.c

    r7121a9fa re6f7f81  
    2424#include <rtems/system.h>
    2525#include <rtems/score/sysstate.h>
    26 #include <rtems/score/heap.h>
     26#include <rtems/score/heapimpl.h>
    2727
    2828static Heap_Resize_status _Heap_Resize_block_checked(
  • cpukit/score/src/heapsizeofuserarea.c

    r7121a9fa re6f7f81  
    2222#include <rtems/system.h>
    2323#include <rtems/score/sysstate.h>
    24 #include <rtems/score/heap.h>
     24#include <rtems/score/heapimpl.h>
    2525
    2626bool _Heap_Size_of_alloc_area(
  • cpukit/score/src/heapwalk.c

    r7121a9fa re6f7f81  
    2323#include <rtems/score/address.h>
    2424#include <rtems/score/sysstate.h>
    25 #include <rtems/score/heap.h>
     25#include <rtems/score/heapimpl.h>
    2626#include <rtems/score/interr.h>
    2727#include <rtems/bspIo.h>
  • cpukit/score/src/wkspace.c

    r7121a9fa re6f7f81  
    1616
    1717#if HAVE_CONFIG_H
    18 #include "config.h"
     18  #include "config.h"
    1919#endif
    2020
    21 #include <rtems/system.h>
     21#include <rtems/score/wkspace.h>
     22#include <rtems/score/heapimpl.h>
     23#include <rtems/score/interr.h>
    2224#include <rtems/config.h>
    23 #include <rtems/score/wkspace.h>
    24 #include <rtems/score/interr.h>
    2525
    2626#include <string.h>  /* for memset */
Note: See TracChangeset for help on using the changeset viewer.