|
@@ -15,7 +15,6 @@
|
|
|
*
|
|
|
*/
|
|
|
|
|
|
-#include <stdio.h>
|
|
|
#include "coalesce.h"
|
|
|
#include "block_header.h"
|
|
|
#include "other.h"
|
|
@@ -100,74 +99,36 @@ bool coalesce(allocator_t **allocator, heap_t *heap, void **ptr) {
|
|
|
three_blocks_size = (size_t) -1; /* SIZE_MAX */
|
|
|
}
|
|
|
|
|
|
- /* /1* Check if Previous + Current + Next is ok *1/ */
|
|
|
- /* if(three_blocks_size <= max_coal_size) { */
|
|
|
- /* /1* If previous block is on a fixed list, remove it *1/ */
|
|
|
-/* #ifdef WITH_FIXED_LISTS */
|
|
|
- /* /1* Check if it is a block of a fixed list *1/ */
|
|
|
- /* fixed_list_id = map_size_to_list(heap, get_size(previous_block)); */
|
|
|
- /* if(fixed_list_id != -1) { */
|
|
|
- /* /1* If it is, find the fixed list and remove the block *1/ */
|
|
|
- /* current_maptable_node = heap->maptable_head; */
|
|
|
- /* if(fixed_list_id != 0) { */
|
|
|
- /* for(i = 1; i < fixed_list_id; i++) { */
|
|
|
- /* current_maptable_node = current_maptable_node->next; */
|
|
|
- /* } */
|
|
|
- /* } */
|
|
|
-/* #ifdef COUNT_HOPS */
|
|
|
- /* remove_block(heap, ptr, ¤t_maptable_node->fixed_list_head); */
|
|
|
-/* #else */
|
|
|
- /* remove_block(ptr, ¤t_maptable_node->fixed_list_head); */
|
|
|
-/* #endif /1* COUNT_HOPS *1/ */
|
|
|
- /* } */
|
|
|
-/* #endif /1* WITH_FIXED_LISTS *1/ */
|
|
|
- /* /1* Remove the next block from any freelist *1/ */
|
|
|
- /* remove_block_from_lists(&next_block, heap); */
|
|
|
- /* /1* Update border pointer if the next block was the border pointer *1/ */
|
|
|
- /* if(allocator->border_ptr == next_block) { */
|
|
|
- /* allocator->border_ptr = previous_block; */
|
|
|
- /* } */
|
|
|
- /* /1* Reset the previous block size *1/ */
|
|
|
- /* set_size_and_free(allocator, previous_block, three_blocks_size); */
|
|
|
- /* return true; */
|
|
|
- /* } */
|
|
|
+ /* Check if Previous + Current + Next is ok */
|
|
|
+ if(three_blocks_size <= max_coal_size) {
|
|
|
+ remove_block_from_lists(&previous_block, heap);
|
|
|
+ /* Remove the next block from any freelist */
|
|
|
+ remove_block_from_lists(&next_block, heap);
|
|
|
+ /* Update border pointer if the next block was the border pointer */
|
|
|
+ if((*allocator)->border_ptr == next_block) {
|
|
|
+ (*allocator)->border_ptr = previous_block;
|
|
|
+ }
|
|
|
+ /* Reset the previous block size */
|
|
|
+ set_size_and_free(*allocator, previous_block, three_blocks_size);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- /* /1* Check if Previous + Current is ok *1/ */
|
|
|
- /* if(previous_current_size <= max_coal_size) { */
|
|
|
- /* /1* If previous block is on a fixed list, remove it *1/ */
|
|
|
-/* #ifdef WITH_FIXED_LISTS */
|
|
|
- /* /1* Check if it is a block of a fixed list *1/ */
|
|
|
- /* fixed_list_id = map_size_to_list(heap, get_size(previous_block)); */
|
|
|
- /* if(fixed_list_id != -1) { */
|
|
|
- /* /1* If it is, find the fixed list and remove the block *1/ */
|
|
|
- /* current_maptable_node = heap->maptable_head; */
|
|
|
- /* if(fixed_list_id != 0) { */
|
|
|
- /* for(i = 1; i < fixed_list_id; i++) { */
|
|
|
- /* current_maptable_node = current_maptable_node->next; */
|
|
|
- /* } */
|
|
|
- /* } */
|
|
|
-/* #ifdef COUNT_HOPS */
|
|
|
- /* remove_block(heap, ptr, ¤t_maptable_node->fixed_list_head); */
|
|
|
-/* #else */
|
|
|
- /* remove_block(ptr, ¤t_maptable_node->fixed_list_head); */
|
|
|
-/* #endif /1* COUNT_HOPS *1/ */
|
|
|
- /* } */
|
|
|
-/* #endif /1* WITH_FIXED_LISTS *1/ */
|
|
|
- /* /1* Update border pointer if the current block was the border pointer *1/ */
|
|
|
- /* if((allocator)->border_ptr == *ptr) { */
|
|
|
- /* (allocator)->border_ptr = previous_block; */
|
|
|
- /* } */
|
|
|
- /* /1* Reset the previous block size *1/ */
|
|
|
- /* set_size_and_free(allocator, *ptr, previous_current_size); */
|
|
|
- /* return true; */
|
|
|
- /* } */
|
|
|
+ /* Check if Previous + Current is ok */
|
|
|
+ if(previous_current_size <= max_coal_size) {
|
|
|
+ /* printf("pcs\n"); */
|
|
|
+ remove_block_from_lists(*ptr, heap);
|
|
|
+ /* Update border pointer if the current block was the border pointer */
|
|
|
+ if((*allocator)->border_ptr == *ptr) {
|
|
|
+ (*allocator)->border_ptr = previous_block;
|
|
|
+ }
|
|
|
+ /* Reset the previous block size */
|
|
|
+ set_size_and_free(*allocator, *ptr, previous_current_size);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
/* Check if Current + Next is ok */
|
|
|
if(current_next_size <= max_coal_size) {
|
|
|
- printf("cnsize = %zu\n", current_next_size);
|
|
|
- if(get_size(next_block) == 0) {
|
|
|
- printf("danger!\n");
|
|
|
- }
|
|
|
+ /* printf("cn\n"); */
|
|
|
remove_block_from_lists(&next_block, heap);
|
|
|
if((*allocator)->border_ptr == next_block) {
|
|
|
(*allocator)->border_ptr = *ptr;
|