1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- /*
- * Copyright 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.
- *
- */
- /**
- * @file src/free.c
- * @author Ioannis Koutras (joko@microlab.ntua.gr)
- * @date September 2012
- *
- * @brief Implementation of the free() call.
- */
- #include <inttypes.h>
- #include "dmmlib/dmmlib.h"
- #include "tls_allocator.h"
- #include "slab.h"
- #include "default_rb.h"
- #include "dmmlib_trace.h"
- #include "locks.h"
- #include "other.h"
- #include "release_memory.h"
- #include "statistics.h"
- void free(void *ptr) {
- raw_block_header_t *owner_raw_block;
- if(ptr == NULL || ptr == (void *) 0xD34D) {
- return;
- }
- #if defined PARSE_ENV && defined WITH_MEM_TRACE
- get_tls_allocator();
- if(__builtin_expect (tls_allocator->initialized, true)) {
- #endif /* PARSE_ENV && WITH_MEM_TRACE */
- MEM_TRACE("dmmlib - f %p\n", ptr);
- #if defined PARSE_ENV && defined WITH_MEM_TRACE
- }
- #endif /* PARSE_ENV && WITH_MEM_TRACE */
- owner_raw_block = find_raw_block_owner(ptr);
- if(owner_raw_block->type == SLAB) {
- slab_rb_t *encapsulated_slab_rb = (slab_rb_t *)
- ((uintptr_t) owner_raw_block + sizeof(raw_block_header_t));
- DEALY_LOCK(owner_raw_block->lock);
- slab_free(encapsulated_slab_rb, ptr);
- DEALY_UNLOCK(owner_raw_block->lock);
- } else if(owner_raw_block->type == FREELIST) {
- DEFAULT_RB_T *encapsulated_rb = (DEFAULT_RB_T *)
- ((uintptr_t) owner_raw_block + sizeof(raw_block_header_t));
- DEALY_LOCK(owner_raw_block->lock);
- dmmlib_free(encapsulated_rb, ptr);
- DEALY_UNLOCK(owner_raw_block->lock);
- } else if(owner_raw_block->type == BIGBLOCK) {
- owner_raw_block = (raw_block_header_t *)
- ((uintptr_t) ptr - sizeof(raw_block_header_t));
- #ifdef WITH_ALLOCATOR_STATS
- #if !defined PARSE_ENV || (defined PARSE_ENV && !defined MEM_TRACE) || \
- !defined COALESCING_VARIABLE
- get_tls_allocator();
- #endif /* !PARSE_ENV || (PARSE_ENV && !MEM_TRACE) || !COALESCING_VARIABLE */
- DEALY_LOCK(tls_allocator->edit_lock);
- update_stats
- ( &tls_allocator->dmm_stats
- , FREE
- #ifdef REQUEST_SIZE_INFO
- , owner_raw_block->requested_size
- #endif /* REQUEST_SIZE_INFO */
- );
- tls_allocator->dmm_stats.total_mem_allocated -= owner_raw_block->size;
- DEALY_UNLOCK(tls_allocator->edit_lock);
- #endif /* WITH_ALLOCATOR_STATS */
- release_memory(owner_raw_block);
- }
- }
|