Changeset 493e405 in rtems for cpukit/score/src/heapallocatealigned.c
 Timestamp:
 09/12/07 20:11:33 (15 years ago)
 Branches:
 4.10, 4.11, 4.8, 4.9, 5, master
 Children:
 98e398cb
 Parents:
 8393f3a
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

cpukit/score/src/heapallocatealigned.c
r8393f3a r493e405 57 57 #endif /* !defined(RTEMS_HEAP_DEBUG) */ 58 58 59 /* 60 * Allocate block of size 'alloc_size' from 'the_block' belonging to 61 * 'the_heap'. Split 'the_block' if possible, otherwise allocate it entirely. 62 * When split, make the upper part used, and leave the lower part free. 63 * Return the block allocated. 64 * 65 * NOTE: this is similar to _Heap_Block_allocate(), except it makes different 66 * part of the split block used, and returns address of the block instead of its 67 * size. We do need such variant for _Heap_Allocate_aligned() as we can't allow 68 * user pointer to be too far from the beginning of the block, so that we can 69 * recover startofblock address from the user pointer without additional 70 * information stored in the heap. 71 */ 72 static 73 Heap_Block *block_allocate( 74 Heap_Control *the_heap, 75 Heap_Block *the_block, 76 uint32_t alloc_size) 77 { 78 Heap_Statistics *const stats = &the_heap>stats; 79 uint32_t const block_size = _Heap_Block_size(the_block); 80 uint32_t const the_rest = block_size  alloc_size; 81 82 _HAssert(_Heap_Is_aligned(block_size, the_heap>page_size)); 83 _HAssert(_Heap_Is_aligned(alloc_size, the_heap>page_size)); 84 _HAssert(alloc_size <= block_size); 85 _HAssert(_Heap_Is_prev_used(the_block)); 86 87 if(the_rest >= the_heap>min_block_size) { 88 /* Split the block so that lower part is still free, and upper part 89 becomes used. */ 90 the_block>size = the_rest  HEAP_PREV_USED; 91 the_block = _Heap_Block_at(the_block, the_rest); 92 the_block>prev_size = the_rest; 93 the_block>size = alloc_size; 94 } 95 else { 96 /* Don't split the block as remainder is either zero or too small to be 97 used as a separate free block. Change 'alloc_size' to the size of the 98 block and remove the block from the list of free blocks. */ 99 _Heap_Block_remove(the_block); 100 alloc_size = block_size; 101 stats>free_blocks = 1; 102 } 103 /* Mark the block as used (in the next block). */ 104 _Heap_Block_at(the_block, alloc_size)>size = HEAP_PREV_USED; 105 /* Update statistics */ 106 stats>free_size = alloc_size; 107 if(stats>min_free_size > stats>free_size) 108 stats>min_free_size = stats>free_size; 109 stats>used_blocks += 1; 110 return the_block; 111 } 112 113 59 114 /*PAGE 60 115 * … … 102 157 /* Find large enough free block that satisfies the alignment requirements. */ 103 158 104 for(the_block = _Heap_ Head(the_heap)>next, search_count = 0;159 for(the_block = _Heap_First(the_heap), search_count = 0; 105 160 the_block != tail; 106 161 the_block = the_block>next, ++search_count) … … 132 187 _Heap_Align_down_uptr(&user_addr, page_size); 133 188 134 /* Make sure 'user_addr' calculated didn't run out of 'the_block . */189 /* Make sure 'user_addr' calculated didn't run out of 'the_block'. */ 135 190 if(user_addr >= user_area) { 136 191 … … 173 228 _HAssert(_Heap_Is_aligned_ptr((void*)aligned_user_addr, alignment)); 174 229 175 (void)_Heap_Block_allocate(the_heap, the_block, alloc_size);230 the_block = block_allocate(the_heap, the_block, alloc_size); 176 231 177 232 stats>searches += search_count + 1;
Note: See TracChangeset
for help on using the changeset viewer.