|
@@ -0,0 +1,64 @@
|
|
|
+/*
|
|
|
+ * 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 "freelist/freelist.h"
|
|
|
+
|
|
|
+#ifdef HAVE_LOCKS
|
|
|
+#include <pthread.h>
|
|
|
+#endif /* HAVE_LOCKS */
|
|
|
+
|
|
|
+#include "freelist/block_header_funcs.h"
|
|
|
+#include "freelist/linked_lists/add_block.h"
|
|
|
+#if defined (COALESCING_FIXED) || defined (COALESCING_VARIABLE)
|
|
|
+#include "freelist/coalesce.h"
|
|
|
+#endif /* COALESCING_FIXED || COALESCING_VARIABLE */
|
|
|
+
|
|
|
+/** Frees the memory block inside of a specific free-list organized raw block.
|
|
|
+ * @param raw_block The pointer of the raw block.
|
|
|
+ * @param ptr The pointer of the memory block to be freed.
|
|
|
+ */
|
|
|
+void freelist_free(raw_block_header_t *raw_block, void *ptr) {
|
|
|
+ freelist_rb_t *rb_header;
|
|
|
+
|
|
|
+ rb_header = (freelist_rb_t *)((char *)raw_block +
|
|
|
+ sizeof(raw_block_header_t));
|
|
|
+ ptr = get_header(ptr);
|
|
|
+
|
|
|
+#ifdef HAVE_LOCKS
|
|
|
+ pthread_mutex_lock(&raw_block->mutex);
|
|
|
+#endif /* HAVE_LOCKS */
|
|
|
+
|
|
|
+ // Memory stats get updated here in case the space gets coalesced with its
|
|
|
+ // free neighbors.
|
|
|
+#ifdef WITH_STATS
|
|
|
+ raw_block->dmm_stats.total_mem_allocated -= get_size(ptr);
|
|
|
+ raw_block->dmm_stats.live_objects--;
|
|
|
+ raw_block->dmm_stats.num_free++;
|
|
|
+#endif /* WITH_STATS */
|
|
|
+
|
|
|
+#if defined (COALESCING_FIXED) || defined (COALESCING_VARIABLE)
|
|
|
+ coalesce(rb_header, ptr);
|
|
|
+#else
|
|
|
+ mark_free(rb_header, ptr);
|
|
|
+ add_block(rb_header, ptr);
|
|
|
+#endif /* COALESCING_FIXED || COALESCING_VARIABLE */
|
|
|
+
|
|
|
+#ifdef HAVE_LOCKS
|
|
|
+ pthread_mutex_unlock(&raw_block->mutex);
|
|
|
+#endif /* HAVE_LOCKS */
|
|
|
+
|
|
|
+}
|