Browse Source

Create WITH_SINGLE_ALLOCATOR flag

Ioannis Koutras 13 years ago
parent
commit
acee701a09

+ 1 - 0
CMakeLists.txt

@@ -34,6 +34,7 @@ endif (WITH_DOC)
 
 message(STATUS "********************************************")
 message(STATUS "********** ${PROJECT_NAME} build options : **********")
+message(STATUS "Support for just one allocator: " ${WITH_SINGLE_ALLOCATOR})
 message(STATUS "OS call for memory requests: " ${WITH_SYSTEM_CALLS})
 message(STATUS "POSIX locking mechanisms: " ${HAVE_LOCKS})
 message(STATUS "Number of heaps per allocator: " ${NUM_HEAPS})

+ 3 - 0
DefineOptions.cmake

@@ -1,3 +1,4 @@
+option(WITH_SINGLE_ALLOCATOR "Build with support of just one allocator" ON)
 option(HAVE_LOCKS "Build with POSIX locking mechanisms" ON)
 option(WITH_REALLOC "Build with realloc" OFF)
 option(WITH_EXAMPLES "Build with examples" OFF)
@@ -40,6 +41,7 @@ option(LEON3 "Build for Leon3" OFF)
 option(LINUXTEST "Build a case for Linux" ON) 
 
 if (P2012)
+  set(WITH_SINGLE_ALLOCATOR OFF)
   set(HAVE_LOCKS OFF)
   set(WITH_SYSTEM_CALLS "none")
   set(WITH_STATIC_LIB ON)
@@ -52,6 +54,7 @@ if (P2012)
 endif (P2012)
 
 if (LEON3)
+  set(WITH_SINGLE_ALLOCATOR OFF)
   set(HAVE_LOCKS OFF)
   set(WITH_SYSTEM_CALLS "none")
   set(WITH_STATIC_LIB ON)

+ 2 - 0
dmm_config.h.in

@@ -3,6 +3,8 @@
 
 #cmakedefine LEON3
 
+#cmakedefine WITH_SINGLE_ALLOCATOR
+
 #cmakedefine HAVE_LOCKS
 
 #cmakedefine NO_SYSTEM_CALLS

+ 0 - 15
include/dmmlib/custom_realloc.h

@@ -40,19 +40,4 @@
  */ 
 void * custom_ahrealloc(allocator_t *allocator, heap_t *heap, void *ptr, size_t size);
 
-
-
-/* In case stdlib.h is used, there is no need to redeclare realloc() */
-#ifndef __malloc_and_calloc_defined
-/**
- * Try to change the size of an allocation
- * \param   ptr	    The pointer to the data part of the original memory block.
- * \param   size    The new desired size of the block.
- *
- * \return  The pointer to the data part of the memory block which
- * has the new, desired size.
- */
-void * realloc(void *ptr, size_t size);
-#endif /* __malloc_and_calloc_defined */
-
 #endif /* CUSTOM_REALLOC_H */

+ 4 - 10
include/dmmlib/dmmlib.h

@@ -21,17 +21,11 @@
 #include <dmmlib/heap.h>
 #include <dmmlib/custom_realloc.h>
 
+#ifdef WITH_SINGLE_ALLOCATOR
+#include <dmmlib/single_allocator.h>
+#endif /* WITH_SINGLE_ALLOCATOR */
+
 void * custom_ahmalloc(allocator_t* allocator, heap_t* heap, size_t size);
 void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr);
 
-/* In case stdlib.h is used, there is no need to redeclare
- * malloc() and free()
- */
-#ifndef __malloc_and_calloc_defined
-void * malloc(size_t size);
-void free(void *ptr);
-#endif /* __malloc_and_calloc_defined */
-
-allocator_t systemallocator;
-
 #endif /* DMMLIB_H */

+ 61 - 0
include/dmmlib/single_allocator.h

@@ -0,0 +1,61 @@
+/*
+ *   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.
+ *
+ */
+
+/**
+ * \file 	single_allocator.h
+ * \author 	Ioannis Koutras (joko@microlab.ntua.gr)
+ * \date 	September, 2011
+ * 	Basic structures needed for the dmmlib allocator.
+ */
+
+#ifndef SINGLE_ALLOCATOR_H
+#define SINGLE_ALLOCATOR_H
+
+#include <dmmlib/heap.h>
+
+/* In case stdlib.h is used, there is no need to redeclare
+ * malloc() and free()
+ */
+#ifndef __malloc_and_calloc_defined
+/**
+ * Allocates size bytes by using the system's allocator.
+ * \param   size    Requested allocation size in bytes.
+ */
+void * malloc(size_t size);
+
+/**
+ * De-allocates the memory space pointed to by ptr.
+ * \param   ptr     The pointer to memory to free.
+ */
+void free(void *ptr);
+
+/**
+ * Try to change the size of an allocation
+ * \param   ptr	    The pointer to the data part of the original memory block.
+ * \param   size    The new desired size of the block.
+ *
+ * \return  The pointer to the data part of the memory block which
+ * has the new, desired size.
+ */
+void * realloc(void *ptr, size_t size);
+
+#endif /* __malloc_and_calloc_defined */
+
+/** Global variable storing allocator's settings */
+allocator_t systemallocator;
+
+#endif /* SINGLE_ALLOCATOR_H */

+ 7 - 0
src/CMakeLists.txt

@@ -39,6 +39,13 @@ set(dmmlib_SRCS
   sys_alloc.c
 )
 
+if (WITH_SINGLE_ALLOCATOR)
+  set(dmmlib_SRCS
+    ${dmmlib_SRCS}
+    single_allocator.c
+  )
+endif (WITH_SINGLE_ALLOCATOR)
+
 if (HAVE_LOCKS)
   find_package (Threads)
   set(dmmlib_SRCS

+ 0 - 18
src/custom_free.c

@@ -239,21 +239,3 @@ void custom_ahfree(allocator_t *allocator, heap_t* heap, void *ptr) {
     posix_unlock(heap);
 #endif /* HAVE_LOCKS */
 }
-
-void free(void *ptr) {
-    allocator_t *allocator;
-    heap_t *heap;
-    int heap_id;
-
-    allocator = &systemallocator;
-
-    /* FIXME Space aware allocators currently use one heap */
-#ifdef NO_SYSTEM_CALLS
-    heap_id = 0;
-#else /* NO_SYSTEM_CALLS */
-    heap_id = map_thread_heap();
-#endif /* NO_SYSTEM_CALLS */
-    heap = &allocator->heaps[heap_id];
-
-    custom_ahfree(allocator, heap, ptr);
-}

+ 0 - 26
src/custom_malloc.c

@@ -23,7 +23,6 @@
 #if defined (SPLITTING_FIXED) || defined (SPLITTING_VARIABLE)
 #include "split.h"
 #endif /* SPLITTING_FIXED || SPLITTING_VARIABLE */
-#include <dmmlib/initialize_allocator.h>
 #include "other.h"
 #include "linked_lists/linked_lists.h"
 #include "linked_lists/search_algorithms.h"
@@ -147,28 +146,3 @@ void * custom_ahmalloc(allocator_t* allocator, heap_t* heap, size_t size) {
 
     return ptr;
 }
-
-void * malloc(size_t size) {
-    allocator_t *allocator;
-    heap_t *heap;
-    int heap_id;
-
-    allocator = &systemallocator;
-    /* Space aware allocators have to be already initialized, no need to do
-     * that here. */
-#ifndef NO_SYSTEM_CALLS
-    if(allocator->initialized != true) {
-        initialize_allocator(allocator);
-    }
-#endif /* NO_SYSTEM_CALLS */
-
-    /* FIXME Space aware allocators currently use one heap */
-#ifdef NO_SYSTEM_CALLS
-    heap_id = 0;
-#else /* NO_SYSTEM_CALLS */
-    heap_id = map_thread_heap();
-#endif /* NO_SYSTEM_CALLS */
-    heap = &allocator->heaps[heap_id];
-
-    return custom_ahmalloc(allocator, heap, size);
-}

+ 0 - 25
src/custom_realloc.c

@@ -166,28 +166,3 @@ void * custom_ahrealloc(allocator_t *allocator, heap_t *heap, void *ptr, size_t
         return custom_ahmalloc(allocator, heap, size);
     }
 }
-
-void * realloc(void *ptr, size_t size) {
-    allocator_t *allocator;
-    heap_t *heap;
-    int heap_id;
-
-    allocator = &systemallocator;
-    /* Space aware allocators have to be already initialized, no need to do
-     * that here. */
-#ifndef NO_SYSTEM_CALLS
-    if(allocator->initialized != true) {
-        initialize_allocator(allocator);
-    }
-#endif /* NO_SYSTEM_CALLS */
-
-    /* FIXME Space aware allocators currently use one heap */
-#ifdef NO_SYSTEM_CALLS
-    heap_id = 0;
-#else /* NO_SYSTEM_CALLS */
-    heap_id = map_thread_heap();
-#endif /* NO_SYSTEM_CALLS */
-    heap = &allocator->heaps[heap_id];
-
-    return custom_ahrealloc(allocator, heap, ptr, size);
-}

+ 98 - 0
src/single_allocator.c

@@ -0,0 +1,98 @@
+/*
+ *   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.
+ *
+ */
+
+/**
+ * \file    single_allocator.c
+ * \author  Ioannis Koutras (joko@microlab.ntua.gr)
+ * \date    March, 2012
+ *
+ * \brief   Implementations of malloc(), free() and realloc() calls while using
+ * just one allocator.
+ */
+
+#include <dmmlib/single_allocator.h>
+#include <dmmlib/initialize_allocator.h>
+#include "other.h"
+#include <dmmlib/dmmlib.h>
+
+void * malloc(size_t size) {
+    allocator_t *allocator;
+    heap_t *heap;
+    int heap_id;
+
+    allocator = &systemallocator;
+    /* Space aware allocators have to be already initialized, no need to do
+     * that here. */
+#ifndef NO_SYSTEM_CALLS
+    if(allocator->initialized != true) {
+        initialize_allocator(allocator);
+    }
+#endif /* NO_SYSTEM_CALLS */
+
+    /* FIXME Space aware allocators currently use one heap */
+#ifdef NO_SYSTEM_CALLS
+    heap_id = 0;
+#else /* NO_SYSTEM_CALLS */
+    heap_id = map_thread_heap();
+#endif /* NO_SYSTEM_CALLS */
+    heap = &allocator->heaps[heap_id];
+
+    return custom_ahmalloc(allocator, heap, size);
+}
+
+void free(void *ptr) {
+    allocator_t *allocator;
+    heap_t *heap;
+    int heap_id;
+
+    allocator = &systemallocator;
+
+    /* FIXME Space aware allocators currently use one heap */
+#ifdef NO_SYSTEM_CALLS
+    heap_id = 0;
+#else /* NO_SYSTEM_CALLS */
+    heap_id = map_thread_heap();
+#endif /* NO_SYSTEM_CALLS */
+    heap = &allocator->heaps[heap_id];
+
+    custom_ahfree(allocator, heap, ptr);
+}
+
+void * realloc(void *ptr, size_t size) {
+    allocator_t *allocator;
+    heap_t *heap;
+    int heap_id;
+
+    allocator = &systemallocator;
+    /* Space aware allocators have to be already initialized, no need to do
+     * that here. */
+#ifndef NO_SYSTEM_CALLS
+    if(allocator->initialized != true) {
+        initialize_allocator(allocator);
+    }
+#endif /* NO_SYSTEM_CALLS */
+
+    /* FIXME Space aware allocators currently use one heap */
+#ifdef NO_SYSTEM_CALLS
+    heap_id = 0;
+#else /* NO_SYSTEM_CALLS */
+    heap_id = map_thread_heap();
+#endif /* NO_SYSTEM_CALLS */
+    heap = &allocator->heaps[heap_id];
+
+    return custom_ahrealloc(allocator, heap, ptr, size);
+}