source: rtems/cpukit/score/src/heapextend.c @ 962e894f

4.104.114.84.95
Last change on this file since 962e894f was 962e894f, checked in by Joel Sherrill <joel.sherrill@…>, on 01/20/05 at 18:22:29

2005-01-20 Sergei Organov <osv@…>

PR 536/rtems
Heap manager re-implementation to consume less memory and still satisfy
alignment requirements.


  • score/src/heap.c, score/src/heapallocate.c, score/src/heapextend.c, score/src/heapfree.c, score/src/heapgetinfo.c, score/src/heapgetfreeinfo.c, core/src/heapsizeofuserarea.c, score/src/heapwalk.c, core/macros/rtems/score/heap.inl, score/inline/rtems/score/heap.inl, score/include/rtems/score/heap.h: Reimplemented.
  • score/src/heapallocatealigned.c: new file
  • score/Makefile.am: HEAP_C_FILES: add score/src/heapallocatealigned.c
  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 *  Heap Handler
3 *
4 *  COPYRIGHT (c) 1989-1999.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14
15#include <rtems/system.h>
16#include <rtems/score/sysstate.h>
17#include <rtems/score/heap.h>
18
19/*PAGE
20 *
21 *  _Heap_Extend
22 *
23 *  This routine grows the_heap memory area using the size bytes which
24 *  begin at starting_address.
25 *
26 *  Input parameters:
27 *    the_heap          - pointer to heap header.
28 *    starting_address  - pointer to the memory area.
29 *    size              - size in bytes of the memory block to allocate.
30 *
31 *  Output parameters:
32 *    *amount_extended  - amount of memory added to the_heap
33 */
34
35Heap_Extend_status _Heap_Extend(
36  Heap_Control        *the_heap,
37  void                *starting_address,
38  uint32_t             size,
39  uint32_t            *amount_extended
40)
41{
42  uint32_t         the_size;
43  Heap_Statistics *const stats = &the_heap->stats;
44
45  /*
46   *  The overhead was taken from the original heap memory.
47   */
48
49  Heap_Block  *old_final;
50  Heap_Block  *new_final;
51
52  /*
53   *  There are five possibilities for the location of starting
54   *  address:
55   *
56   *    1. non-contiguous lower address     (NOT SUPPORTED)
57   *    2. contiguous lower address         (NOT SUPPORTED)
58   *    3. in the heap                      (ERROR)
59   *    4. contiguous higher address        (SUPPORTED)
60   *    5. non-contiguous higher address    (NOT SUPPORTED)
61   *
62   *  As noted, this code only supports (4).
63   */
64
65  if ( starting_address >= the_heap->begin &&        /* case 3 */
66       starting_address < the_heap->end
67     )
68    return HEAP_EXTEND_ERROR;
69
70  if ( starting_address != the_heap->end )
71    return HEAP_EXTEND_NOT_IMPLEMENTED;         /* cases 1, 2, and 5 */
72
73  /*
74   *  Currently only case 4 should make it to this point.
75   *  The basic trick is to make the extend area look like a used
76   *  block and free it.
77   */
78
79  old_final = the_heap->final;
80  the_heap->end = _Addresses_Add_offset( the_heap->end, size );
81  the_size = _Addresses_Subtract( the_heap->end, old_final ) - HEAP_OVERHEAD;
82  _Heap_Align_down( &the_size, the_heap->page_size );
83
84  *amount_extended = size;
85
86  if( the_size < the_heap->min_block_size )
87    return HEAP_EXTEND_SUCCESSFUL;
88
89  old_final->size = the_size | (old_final->size & HEAP_PREV_USED);
90  new_final = _Heap_Block_at( old_final, the_size );
91  new_final->size = HEAP_PREV_USED;
92  the_heap->final = new_final;
93
94  stats->size += size;
95  stats->used_blocks += 1;
96  stats->frees -= 1;    /* Don't count subsequent call as actual free() */
97
98  _Heap_Free( the_heap, _Heap_User_area( old_final ) );
99
100  return HEAP_EXTEND_SUCCESSFUL;
101}
Note: See TracBrowser for help on using the repository browser.