source: rtems/cpukit/score/src/heapallocate.c @ 371cea31

4.104.115
Last change on this file since 371cea31 was 371cea31, checked in by Joel Sherrill <joel.sherrill@…>, on 08/26/09 at 12:00:24

2009-08-24 Sebastian Huber <Sebastian.Huber@…>

  • libmisc/stackchk/check.c, rtems/src/regionreturnsegment.c, rtems/src/regiongetsegmentsize.c, src/heapalignupuptr.c, src/heapallocatealigned.c, src/heapallocate.c, src/heap.c, src/heapextend.c, src/heapfree.c, src/heapgetfreeinfo.c, src/heapgetinfo.c, src/heapresizeblock.c, src/heapsizeofuserarea.c, src/heapwalk.c, src/pheapgetblocksize.c, inline/rtems/score/heap.inl, include/rtems/score/heap.h: Overall cleanup. Changed all types for addresses, sizes, offsets and alignments to uintptr_t. Reformatted. Added variables for clarity. Renamed various objects. Enabled _HAssert() for all instances. More changes follow.
  • Property mode set to 100644
File size: 1.6 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#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <rtems/system.h>
19#include <rtems/score/sysstate.h>
20#include <rtems/score/heap.h>
21
22void *_Heap_Allocate( Heap_Control *heap, uintptr_t size )
23{
24  Heap_Statistics *const stats = &heap->stats;
25  Heap_Block * const tail = _Heap_Free_list_tail( heap );
26  Heap_Block *block = _Heap_First_free_block( heap );
27  uint32_t search_count = 0;
28  void *alloc_area_begin_ptr = NULL;
29
30  size = _Heap_Calc_block_size( size, heap->page_size, heap->min_block_size );
31  if( size == 0 ) {
32    return NULL;
33  }
34
35  /*
36   * Find large enough free block.
37   *
38   * Do not bother to mask out the HEAP_PREV_BLOCK_USED bit as it will not
39   * change the result of the size comparison.
40   */
41  while (block != tail && block->size_and_flag < size) {
42    _HAssert( _Heap_Is_prev_used( block ));
43
44    block = block->next;
45    ++search_count;
46  }
47
48  if (block != tail) {
49    _Heap_Block_allocate( heap, block, size );
50
51    alloc_area_begin_ptr = (void *) _Heap_Alloc_area_of_block( block );
52
53    _HAssert( _Heap_Is_aligned( (uintptr_t) alloc_area_begin_ptr, heap->page_size ));
54
55    /* Statistics */
56    ++stats->allocs;
57    stats->searches += search_count;
58  }
59
60  /* Statistics */
61  if (stats->max_search < search_count) {
62    stats->max_search = search_count;
63  }
64
65  return alloc_area_begin_ptr;
66}
Note: See TracBrowser for help on using the repository browser.