Browse Source

Separated freelist_free() from freelist_malloc.c source file

Ioannis Koutras 12 years ago
parent
commit
5f87961d48

+ 6 - 5
private-include/freelist/freelist_malloc.h

@@ -16,13 +16,14 @@
  */
 
 /**
- * \file    freelist_malloc.h
+ * \file    freelist.h
  * \author  Ioannis Koutras (joko@microlab.ntua.gr)
- * \brief   Memory allocation for free-list based raw blocks
+ * \brief   Memory allocation and de-allocation for free-list based raw blocks
  */
 
-#ifndef FREELIST_MALLOC_H
-#define FREELIST_MALLOC_H
+#ifndef FREELIST_H
+#define FREELIST_H
+#include "dmm_config.h"
 
 #include "dmmlib/raw_block.h"
 
@@ -38,4 +39,4 @@ void * freelist_malloc(raw_block_header_t *raw_block, size_t size);
 
 void freelist_free(raw_block_header_t *raw_block, void *ptr);
 
-#endif /* FREELIST_MALLOC_H */
+#endif /* FREELIST_H */

+ 1 - 0
src/CMakeLists.txt

@@ -43,6 +43,7 @@ if(RAW_BLOCKS_TYPE STREQUAL "freelist")
     freelist/linked_lists/linked_lists.c
     freelist/linked_lists/search_algorithms.c
     freelist/freelist_malloc.c
+    freelist/freelist_free.c
     )
 
   if(SORT_POLICY STREQUAL "lifo")

+ 1 - 1
src/dmmlib.c

@@ -25,7 +25,7 @@
 
 #include "dmmlib/dmmlib.h"
 #ifdef FL_RB_ONLY
-#include "freelist/freelist_malloc.h"
+#include "freelist/freelist.h"
 #include "freelist/freelist_rb.h"
 #endif /* FL_RB_ONLY */
 #ifdef BITMAP_RB_ONLY

+ 64 - 0
src/freelist/freelist_free.c

@@ -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 */
+
+}

+ 1 - 45
src/freelist/freelist_malloc.c

@@ -15,8 +15,7 @@
  *
  */
 
-#include <dmmlib/dmmlib.h>
-#include "dmm_config.h"
+#include "freelist/freelist.h"
 
 #ifdef HAVE_LOCKS
 #include <pthread.h>
@@ -30,8 +29,6 @@
 #include "freelist/split.h"
 #endif /* SPLITTING_FIXED || SPLITTING_VARIABLE */
 
-#include "freelist/freelist_malloc.h"
-
 #if defined (BEST_FIT)
 #define search_on_free(size) best_fit_on_freelist(rb_header, size)
 #elif defined (GOOD_FIT)
@@ -149,44 +146,3 @@ void * freelist_malloc(raw_block_header_t *raw_block, size_t size) {
         return NULL;
     }
 }
-
-#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 */
-
-}