浏览代码

seperate freelist organization's initialization

Ioannis Koutras 12 年之前
父节点
当前提交
a0f3259810
共有 6 个文件被更改,包括 81 次插入10 次删除
  1. 1 1
      DefineOptions.cmake
  2. 7 0
      include/dmmlib/CMakeLists.txt
  3. 31 0
      include/freelist/initialize.h
  4. 1 0
      src/CMakeLists.txt
  5. 38 0
      src/freelist/initialize.c
  6. 3 9
      src/raw_block.c

+ 1 - 1
DefineOptions.cmake

@@ -1,5 +1,5 @@
 set(WITH_SYSTEM_CALLS "none" CACHE STRING "Choose what system calls can be used, options are: none, sbrk, mmap")
-set(RAW_BLOCKS_TYPE "bitmap" CACHE STRING "Choose what raw blocks can be used, options are: freelist, bitmap")
+set(RAW_BLOCKS_TYPE "freelist" CACHE STRING "Choose what raw blocks can be used, options are: freelist, bitmap")
 option(HAVE_LOCKS "Build with POSIX locking mechanisms" ON)
 option(WITH_REALLOC "Build with realloc" OFF)
 set(TRACE_LEVEL 2 CACHE INTEGER "Choose the trace level, options are: 0, 1, 2 and 3")

+ 7 - 0
include/dmmlib/CMakeLists.txt

@@ -7,6 +7,13 @@ set(dmmlib_HDRS
   raw_block.h
 )
 
+if(RAW_BLOCKS_TYPE STREQUAL "freelist")
+  set(dmmlib_HDRS
+    ${dmmlib_HDRS}
+    freelist/initialize.h
+    )
+endif(RAW_BLOCKS_TYPE STREQUAL "freelist")
+
 install(
   FILES
     ${dmmlib_HDRS}

+ 31 - 0
include/freelist/initialize.h

@@ -0,0 +1,31 @@
+/*
+ *   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.
+ *
+ */
+
+#ifndef FL_INITIALIZE_H
+#define FL_INITIALIZE_H
+
+#include <stddef.h>
+
+/** Initializes the free-list organization inside a raw block.
+ *
+ * @param address        The address of the free-list metadata
+ * @param available_size The available size of the raw block for free-list
+ *                       metadata and memory blocks
+ */
+void initialize_freelist(void *address, size_t available_size);
+
+#endif /* FL_INITIALIZE_H */

+ 1 - 0
src/CMakeLists.txt

@@ -47,6 +47,7 @@ if(RAW_BLOCKS_TYPE STREQUAL "freelist")
     freelist/freelist_malloc.c
     freelist/freelist_free.c
     freelist/freelist_realloc.c
+    freelist/initialize.c
     )
 
   if(SORT_POLICY STREQUAL "lifo")

+ 38 - 0
src/freelist/initialize.c

@@ -0,0 +1,38 @@
+/*
+ *   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   initialize.c
+ * @author Ioannis Koutras (joko@microlab.ntua.gr)
+ * @date   October 2012
+ *
+ * @brief  Implementation of free-list initialization.
+ */
+
+
+#include "freelist/initialize.h"
+#include "freelist/freelist_rb.h"
+
+void initialize_freelist(void *address, size_t available_size) {
+    freelist_rb_t *fl_rb = (freelist_rb_t *)address;
+
+    fl_rb->remaining_size = available_size - sizeof(freelist_rb_t);
+    fl_rb->border_ptr = NULL;
+    fl_rb->free_list_head = NULL;
+
+    return;
+}

+ 3 - 9
src/raw_block.c

@@ -23,6 +23,7 @@
 #include "request_memory.h"
 #ifdef FL_RB_ONLY
 #include "freelist/freelist_rb.h"
+#include "freelist/initialize.h"
 #endif /* FL_RB_ONLY */
 #ifdef BITMAP_RB_ONLY
 #include "bitmap/bitmap_rb.h"
@@ -30,9 +31,6 @@
 
 raw_block_header_t *create_raw_block(size_t raw_block_size, rb_type type) {
     void *ptr;
-#ifdef FL_RB_ONLY
-    freelist_rb_t *fl_rb;
-#endif /* FL_RB_ONLY */
 #ifdef BITMAP_RB_ONLY
     bitmap_rb_t *bitmap_rb;
     BMAP_EL_TYPE *bitmap_p;
@@ -51,12 +49,8 @@ raw_block_header_t *create_raw_block(size_t raw_block_size, rb_type type) {
 
 #ifdef FL_RB_ONLY
         case FREELIST:
-            fl_rb = (freelist_rb_t *)((char *)ptr +
-                    sizeof(raw_block_header_t));
-            fl_rb->remaining_size = raw_block_size -
-                sizeof(raw_block_header_t) - sizeof(freelist_rb_t);
-            fl_rb->border_ptr = NULL;
-            fl_rb->free_list_head = NULL;
+            initialize_freelist((char *) ptr + sizeof(raw_block_header_t),
+                    raw_block_size - sizeof(raw_block_header_t));
             break;
 #endif /* FL_RB_ONLY */