Browse Source

clean up more define guards in top-level files

Ioannis Koutras 12 years ago
parent
commit
4bbf6ecc0f
4 changed files with 63 additions and 82 deletions
  1. 49 0
      private-include/default_rb.h
  2. 3 24
      src/free.c
  3. 4 31
      src/malloc.c
  4. 7 27
      src/realloc.c

+ 49 - 0
private-include/default_rb.h

@@ -0,0 +1,49 @@
+/*
+ *   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   default_rb.h
+ * @author Ioannis Koutras (joko@microlab.ntua.gr)
+ * @date   October 2012
+ *
+ * @brief  Include libraries and defines for default raw block selection.
+ */
+
+#ifndef DEFAULT_RB_H
+#define DEFAULT_RB_H
+
+#include "dmm_config.h"
+
+#ifdef BITMAP_RB_ONLY
+#include "bitmap/bitmap.h"
+#include "bitmap/bitmap_rb.h"
+/** Default raw block data type */
+#define DEFAULT_RB_T bitmap_rb_t
+/** Default raw block enumeration type */
+#define DEFAULT_RB_TYPE BITMAP
+#endif /* BITMAP_RB_ONLY */
+
+#ifdef FL_RB_ONLY
+#include "dmmlib/freelist/freelist.h"
+#include "dmmlib/freelist/freelist_rb.h"
+/** Default raw block data type */
+#define DEFAULT_RB_T freelist_rb_t
+/** Default raw block enumeration type */
+#define DEFAULT_RB_TYPE FREELIST
+#endif /* FL_RB_ONLY */
+
+#endif /* DEFAULT_RB_H */

+ 3 - 24
src/free.c

@@ -30,15 +30,7 @@
 
 #include "locks.h"
 
-#ifdef BITMAP_RB_ONLY
-#include "bitmap/bitmap.h"
-#include "bitmap/bitmap_rb.h"
-#endif /* BITMAP_RB_ONLY */
-
-#ifdef FL_RB_ONLY
-#include "dmmlib/freelist/freelist.h"
-#include "dmmlib/freelist/freelist_rb.h"
-#endif /* FL_RB_ONLY */
+#include "default_rb.h"
 
 #ifdef WITH_ALLOCATOR_STATS
 #include "statistics.h"
@@ -46,7 +38,6 @@
 
 #include "release_memory.h"
 
-
 #include "trace.h"
 
 void free(void *ptr) {
@@ -74,20 +65,8 @@ void free(void *ptr) {
 
     if(found == true) {
 
-#ifdef BITMAP_RB_ONLY
-        bitmap_rb_t
-#endif /* BITMAP_RB_ONLY */
-#ifdef FL_RB_ONLY
-        freelist_rb_t
-#endif /* FL_RB_ONLY */
-            *encapsulated_rb = 
-#ifdef BITMAP_RB_ONLY
-                (bitmap_rb_t *)
-#endif /* BITMAP_RB_ONLY */
-#ifdef FL_RB_ONLY
-                (freelist_rb_t *)
-#endif /* FL_RB_ONLY */
-                ((uintptr_t) current_raw_block + sizeof(raw_block_header_t));
+        DEFAULT_RB_T *encapsulated_rb = (DEFAULT_RB_T *)
+            ((uintptr_t) current_raw_block + sizeof(raw_block_header_t));
 
         lock_raw_block(current_raw_block);
         dmmlib_free(encapsulated_rb, ptr);

+ 4 - 31
src/malloc.c

@@ -29,15 +29,7 @@
 
 #include "locks.h"
 
-#ifdef BITMAP_RB_ONLY
-#include "bitmap/bitmap.h"
-#include "bitmap/bitmap_rb.h"
-#endif /* BITMAP_RB_ONLY */
-
-#ifdef FL_RB_ONLY
-#include "dmmlib/freelist/freelist.h"
-#include "dmmlib/freelist/freelist_rb.h"
-#endif /* FL_RB_ONLY */
+#include "default_rb.h"
 
 #ifdef WITH_ALLOCATOR_STATS
 #include "statistics.h"
@@ -63,18 +55,11 @@ void * malloc(size_t size) {
         return NULL;
     }
     
-
     /* Try to find a raw block available for allocation */
 
     while(raw_block != NULL) {
         lock_raw_block(raw_block);
-        encapsulated_rb =
-#ifdef BITMAP_RB_ONLY
-            (bitmap_rb_t *)
-#endif /* BITMAP_RB_ONLY */
-#ifdef FL_RB_ONLY
-            (freelist_rb_t *)
-#endif /* FL_RB_ONLY */
+        encapsulated_rb = (DEFAULT_RB_T *)
             ((uintptr_t) raw_block + sizeof(raw_block_header_t));
         ptr = dmmlib_malloc(encapsulated_rb, size);
         unlock_raw_block(raw_block);
@@ -136,26 +121,14 @@ void * malloc(size_t size) {
 
             lock_global();
             new_raw_block = create_raw_block((size_t) SYS_ALLOC_SIZE,
-#ifdef FL_RB_ONLY
-                    FREELIST
-#endif /* FL_RB_ONLY */
-#ifdef BITMAP_RB_ONLY
-                    BITMAP
-#endif /* BITMAP_RB_ONLY */
-                    );
+                    DEFAULT_RB_TYPE);
             if(new_raw_block != NULL) {
                 new_raw_block->next_raw_block = systemallocator.raw_block_head;
                 systemallocator.raw_block_head = new_raw_block;
                 unlock_global();
 
                 lock_raw_block(new_raw_block);
-                encapsulated_rb =
-#ifdef BITMAP_RB_ONLY
-                    (bitmap_rb_t *)
-#endif /* BITMAP_RB_ONLY */
-#ifdef FL_RB_ONLY
-                    (freelist_rb_t *)
-#endif /* FL_RB_ONLY */
+                encapsulated_rb = (DEFAULT_RB_T *)
                     ((uintptr_t) new_raw_block + sizeof(raw_block_header_t));
                 ptr = dmmlib_malloc(encapsulated_rb, size);
                 unlock_raw_block(new_raw_block);

+ 7 - 27
src/realloc.c

@@ -27,15 +27,7 @@
 
 #include <stdbool.h>
 
-#ifdef BITMAP_RB_ONLY
-#include "bitmap/bitmap.h"
-#include "bitmap/bitmap_rb.h"
-#endif /* BITMAP_RB_ONLY */
-
-#ifdef FL_RB_ONLY
-#include "dmmlib/freelist/freelist.h"
-#include "dmmlib/freelist/freelist_rb.h"
-#endif /* FL_RB_ONLY */
+#include "default_rb.h"
 
 #include "release_memory.h"
 #include <sys/mman.h>
@@ -74,20 +66,8 @@ void * realloc(void *ptr, size_t size) {
 
     if(found == true) {
 
-#ifdef BITMAP_RB_ONLY
-        bitmap_rb_t
-#endif /* BITMAP_RB_ONLY */
-#ifdef FL_RB_ONLY
-        freelist_rb_t
-#endif /* FL_RB_ONLY */
-            *encapsulated_rb = 
-#ifdef BITMAP_RB_ONLY
-                (bitmap_rb_t *)
-#endif /* BITMAP_RB_ONLY */
-#ifdef FL_RB_ONLY
-                (freelist_rb_t *)
-#endif /* FL_RB_ONLY */
-                ((char *)current_raw_block + sizeof(raw_block_header_t));
+        DEFAULT_RB_T *encapsulated_rb = (DEFAULT_RB_T *)
+            ((uintptr_t) current_raw_block + sizeof(raw_block_header_t));
         
         return_ptr = dmmlib_realloc(encapsulated_rb, ptr, size);
         goto done;
@@ -99,8 +79,8 @@ void * realloc(void *ptr, size_t size) {
         // greater, a new big block is initialized, data is copied there and the
         // old big block gets de-allocated.
 
-        current_raw_block = (raw_block_header_t *)((char *)ptr -
-                sizeof(raw_block_header_t));
+        current_raw_block = (raw_block_header_t *)
+            ((uintptr_t) ptr - sizeof(raw_block_header_t));
 
         size_t full_size = sizeof(raw_block_header_t) + size;
 
@@ -110,7 +90,7 @@ void * realloc(void *ptr, size_t size) {
             current_raw_block->size = full_size;
 
             // FIXME This is mmap-specific
-            munmap((void *)((char *)current_raw_block +
+            munmap((void *)((uintptr_t) current_raw_block +
                         current_raw_block->size), remaining_size);
 
 #ifdef WITH_ALLOCATOR_STATS
@@ -144,7 +124,7 @@ void * realloc(void *ptr, size_t size) {
 
             } else {
 
-                memcpy((void *)((char *)new_block +
+                memcpy((void *)((uintptr_t) new_block +
                             sizeof(raw_block_header_t)), ptr,
                         current_raw_block->size - sizeof(raw_block_header_t));