Changeset 6ccfe72 in rtems


Ignore:
Timestamp:
Aug 9, 2012, 8:17:42 AM (8 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
e4278f2
Parents:
3b978e19
git-author:
Sebastian Huber <sebastian.huber@…> (08/09/12 08:17:42)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/25/12 12:54:06)
Message:

score: Change _Heap_Extend() API

The _Heap_Extend() has now the same signature as _Heap_Initialize().
The 4th parameter is ignored (page size in _Heap_Initialize()).

Add Heap_Area and Heap_Initialization_or_extend_handler.

Add and test _Heap_No_extend().

This helps to do a table based heap initialization and extension.
Create a table of Heap_Area elements and iterate through it. Set the
handler to _Heap_Initialize() in the first iteration and then to
_Heap_Extend().

Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • cpukit/rtems/src/regionextend.c

    r3b978e19 r6ccfe72  
    4747{
    4848  uintptr_t           amount_extended;
    49   bool                extend_ok;
    5049  Objects_Locations   location;
    5150  rtems_status_code   return_status;
     
    6261      case OBJECTS_LOCAL:
    6362
    64         extend_ok = _Heap_Extend(
     63        amount_extended = _Heap_Extend(
    6564          &the_region->Memory,
    6665          starting_address,
    6766          length,
    68           &amount_extended
     67          0
    6968        );
    7069
    71         if ( extend_ok ) {
     70        if ( amount_extended > 0 ) {
    7271          the_region->length                += amount_extended;
    7372          the_region->maximum_segment_size  += amount_extended;
  • cpukit/score/Makefile.am

    r3b978e19 r6ccfe72  
    179179    src/heapfree.c src/heapsizeofuserarea.c src/heapwalk.c src/heapgetinfo.c \
    180180    src/heapgetfreeinfo.c src/heapresizeblock.c src/heapiterate.c \
    181     src/heapgreedy.c
     181    src/heapgreedy.c src/heapnoextend.c
    182182
    183183## OBJECT_C_FILES
  • cpukit/score/include/rtems/score/heap.h

    r3b978e19 r6ccfe72  
    389389
    390390/**
     391 * @brief Heap area structure for table based heap initialization and
     392 * extension.
     393 *
     394 * @see Heap_Initialization_or_extend_handler.
     395 */
     396typedef struct {
     397  void *begin;
     398  uintptr_t size;
     399} Heap_Area;
     400
     401/**
     402 * @brief Heap initialization and extend handler type.
     403 *
     404 * This helps to do a table based heap initialization and extension.  Create a
     405 * table of Heap_Area elements and iterate through it.  Set the handler to
     406 * _Heap_Initialize() in the first iteration and then to _Heap_Extend().
     407 *
     408 * @see Heap_Area, _Heap_Initialize(), _Heap_Extend(), or _Heap_No_extend().
     409 */
     410typedef uintptr_t (*Heap_Initialization_or_extend_handler)(
     411  Heap_Control *heap,
     412  void *area_begin,
     413  uintptr_t area_size,
     414  uintptr_t page_size_or_unused
     415);
     416
     417/**
    391418 * @brief Gets the first and last block for the heap area with begin
    392419 * @a heap_area_begin and size @a heap_area_size.
     
    420447 *
    421448 * Returns the maximum memory available, or zero in case of failure.
     449 *
     450 * @see Heap_Initialization_or_extend_handler.
    422451 */
    423452uintptr_t _Heap_Initialize(
     
    431460 * @brief Extends the memory available for the heap @a heap using the memory
    432461 * area starting at @a area_begin of size @a area_size bytes.
    433  *
    434  * The extended space available for allocation will be returned in
    435  * @a amount_extended.  This pointer may be @c NULL.
    436462 *
    437463 * There are no alignment requirements.  The memory area must be big enough to
     
    441467 * corrupt the heap.
    442468 *
    443  * Returns @c true in case of success, and @c false otherwise.
    444  */
    445 bool _Heap_Extend(
     469 * The unused fourth parameter is provided to have the same signature as
     470 * _Heap_Initialize().
     471 *
     472 * Returns the extended space available for allocation, or zero in case of failure.
     473 *
     474 * @see Heap_Initialization_or_extend_handler.
     475 */
     476uintptr_t _Heap_Extend(
    446477  Heap_Control *heap,
    447478  void *area_begin,
    448479  uintptr_t area_size,
    449   uintptr_t *amount_extended
     480  uintptr_t unused
     481);
     482
     483/**
     484 * @brief This function returns always zero.
     485 *
     486 * This function only returns zero and does nothing else.
     487 *
     488 * Returns always zero.
     489 *
     490 * @see Heap_Initialization_or_extend_handler.
     491 */
     492uintptr_t _Heap_No_extend(
     493  Heap_Control *unused_0,
     494  void *unused_1,
     495  uintptr_t unused_2,
     496  uintptr_t unused_3
    450497);
    451498
  • cpukit/score/src/heapextend.c

    r3b978e19 r6ccfe72  
    109109}
    110110
    111 bool _Heap_Extend(
     111uintptr_t _Heap_Extend(
    112112  Heap_Control *heap,
    113113  void *extend_area_begin_ptr,
    114114  uintptr_t extend_area_size,
    115   uintptr_t *extended_size_ptr
     115  uintptr_t unused __attribute__((unused))
    116116)
    117117{
     
    135135
    136136  if ( extend_area_end < extend_area_begin ) {
    137     return false;
     137    return 0;
    138138  }
    139139
     
    148148  if (!extend_area_ok ) {
    149149    /* For simplicity we reject extend areas that are too small */
    150     return false;
     150    return 0;
    151151  }
    152152
     
    161161      sub_area_end > extend_area_begin && extend_area_end > sub_area_begin
    162162    ) {
    163       return false;
     163      return 0;
    164164    }
    165165
     
    235235  stats->size += extended_size;
    236236
    237   if ( extended_size_ptr != NULL )
    238     *extended_size_ptr = extended_size;
    239 
    240   return true;
    241 }
     237  return extended_size;
     238}
  • cpukit/score/src/pheapextend.c

    r3b978e19 r6ccfe72  
    2929)
    3030{
    31   bool      extend_ok;
    3231  uintptr_t amount_extended;
    3332
    3433  _RTEMS_Lock_allocator();
    35     extend_ok = _Heap_Extend(the_heap, starting_address, size, &amount_extended);
     34    amount_extended = _Heap_Extend( the_heap, starting_address, size, 0 );
    3635  _RTEMS_Unlock_allocator();
    37   return extend_ok;
     36
     37  return amount_extended != 0;
    3838}
    39 
  • testsuites/libtests/malloctest/init.c

    r3b978e19 r6ccfe72  
    985985}
    986986
     987static void test_heap_no_extend(void)
     988{
     989  uintptr_t extended_space = _Heap_No_extend( NULL, 0, 0, 0 );
     990  rtems_test_assert( extended_space == 0 );
     991}
     992
    987993static void test_heap_info(void)
    988994{
     
    11431149  test_heap_cases_1();
    11441150  test_heap_extend();
     1151  test_heap_no_extend();
    11451152  test_heap_info();
    11461153  test_protected_heap_info();
Note: See TracChangeset for help on using the changeset viewer.