1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- /*
- * Copyright 2011 Institute of Communication and Computer Systems (ICCS)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
- #include "coalesce.h"
- #include "block_header.h"
- #include "other.h"
- #include "dmm_config.h"
- void * coalesce(allocator_t *allocator, heap_t *heap, void *ptr, size_t size) {
- void *prev;
- #ifdef WITH_FIXED_LISTS
- int fixed_list_id, i;
- #endif /* WITH_FIXED_LISTS */
- maptable_node_t *current_maptable_node;
- prev = get_dlprevious(ptr);
- #ifdef WITH_FIXED_LISTS
- // Check if it is a block of a fixed list
- fixed_list_id = map_size_to_list(heap, get_size(prev));
- if(fixed_list_id != -1) {
- // If it is, find the fixed list and remove the block
- 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;
- }
- }
- remove_block(&ptr, ¤t_maptable_node->fixed_list_head);
- }
- #endif /* WITH_FIXED_LISTS */
- // Set the new size
- // Note: the rest of the header variables will be set on free().
- set_size_and_free(allocator, prev, size);
- /* If the current block is the allocator's border pointer, update the
- * latter to point to the previous block.
- */
- if(allocator->border_ptr == ptr)
- {
- allocator->border_ptr = prev;
- }
- return prev;
- }
|