Browse Source

Separated public and private include files, examples. Examples are now also built through CMake.

Ioannis Koutras 13 years ago
parent
commit
ee0c809d4a
19 changed files with 32 additions and 37 deletions
  1. 17 0
      CMakeLists.txt
  2. 0 22
      Makefile
  3. 1 1
      custom_free.c
  4. 2 1
      custom_malloc.c
  5. 0 1
      dmm_adaptor.c
  6. 3 3
      larson.c
  7. 0 0
      examples/lran2.h
  8. 1 1
      test.c
  9. 1 1
      dmmlib.h
  10. 0 0
      include/dmmlib/heap.h
  11. 1 1
      posix_lock.c
  12. 0 0
      private-include/block_header.h
  13. 1 1
      coalesce.h
  14. 1 1
      dmm_adaptor.h
  15. 1 1
      dmm_init.h
  16. 1 1
      other.h
  17. 1 1
      posix_lock.h
  18. 0 0
      private-include/sys_alloc.h
  19. 1 1
      sys_alloc.c

+ 17 - 0
CMakeLists.txt

@@ -18,6 +18,16 @@ include_directories("${PROJECT_BINARY_DIR}")
 
 #add_subdirectory(src)
 
+set(DMMLIB_PUBLIC_INCLUDE_DIRS
+  ${CMAKE_SOURCE_DIR}/include
+  CACHE INTERNAL "dmmlib public include directories"
+)
+
+set(DMMLIB_PRIVATE_INCLUDE_DIRS
+	${CMAKE_SOURCE_DIR}/private-include
+	${CMAKE_BINARY_DIR}
+)
+
 set(DMMLIB_SHARED_LIBRARY
   dmm_shared
   CACHE INTERNAL "dmmlib shared library"
@@ -41,5 +51,12 @@ if (HAVE_LOCKS)
 	)
 endif (HAVE_LOCKS)
 
+include_directories(
+	${DMMLIB_PUBLIC_INCLUDE_DIRS}
+	${DMMLIB_PRIVATE_INCLUDE_DIRS}
+)
+
 add_library(${DMMLIB_SHARED_LIBRARY} SHARED ${dmmlib_SRCS})
 
+add_subdirectory(examples)
+

+ 0 - 22
Makefile

@@ -1,22 +0,0 @@
-CC=gcc
-WARNINGS := -Wall -Wextra -pedantic -Wshadow -Wpointer-arith -Wcast-align \
-	-Wwrite-strings -Wmissing-prototypes -Wmissing-declarations \
-	-Wredundant-decls -Wnested-externs -Winline -Wno-long-long \
-	-Wuninitialized -Wconversion -Wstrict-prototypes
-CFLAGS := -g -O -std=c99 $(WARNINGS)
-
-OBJ = posix_lock.o other.o block_header.o sys_alloc.o dmm_init.o coalesce.o dmm_adaptor.o custom_malloc.o custom_free.o
-
-%.o: %.c
-	$(CC) -c -o $@ $< $(CFLAGS)
-
-test: $(OBJ) test.o
-	$(CC) -pthread -o $@ $^ $(CFLAGS)
-
-larson: $(OBJ) larson.o
-	$(CC) -pthread -o $@ $^ $(CFLAGS)
-
-clean:
-	-@$(RM) $(wildcard $(OBJ)) test.o larson.o test larson
-
-.PHONY: all clean test

+ 1 - 1
custom_free.c

@@ -1,4 +1,4 @@
-#include "dmmlib.h"
+#include <dmmlib/dmmlib.h>
 #include "dmm_config.h"
 #include "other.h"
 #ifdef HAVE_LOCKS

+ 2 - 1
custom_malloc.c

@@ -1,4 +1,5 @@
-#include "dmmlib.h"
+#include <dmmlib/dmmlib.h>
+
 #include <stdbool.h>
 #include "dmm_config.h"
 #ifdef HAVE_LOCKS

+ 0 - 1
dmm_adaptor.c

@@ -1,5 +1,4 @@
 #include "dmm_adaptor.h"
-#include "heap.h"
 
 void state_refresh(heap_t *heap) {
     float fragmentation;

+ 3 - 3
larson.c

@@ -4,7 +4,7 @@
 #include <string.h>
 #include <assert.h>
 #include <unistd.h>
-#include "dmmlib.h"
+#include <dmmlib/dmmlib.h>
 #include "lran2.h"
 
 #define MAX_THREADS     100
@@ -279,8 +279,8 @@ int main(void) {
 
     printf("chunk size (min,max): ") ;
     //scanf("%d %d", &min_size, &max_size ) ;
-    min_size = 32;
-    max_size = 256;
+    min_size = 1024;
+    max_size = 5012;
 
     printf("threads (min, max):   ") ; 
     //scanf("%d %d", &min_threads, &max_threads) ;

lran2.h → examples/lran2.h


+ 1 - 1
test.c

@@ -1,5 +1,5 @@
 #include <stdio.h>
-#include "dmmlib.h"
+#include <dmmlib/dmmlib.h>
 
 int main(void) {
     void *p1, *p2, *p3;

+ 1 - 1
dmmlib.h

@@ -1,5 +1,5 @@
 #ifndef DMMLIB_H
-#include "heap.h"
+#include <dmmlib/heap.h>
 
 static allocator_t systemallocator;
 

heap.h → include/dmmlib/heap.h


+ 1 - 1
posix_lock.c

@@ -1,5 +1,5 @@
-#include <pthread.h>
 #include "posix_lock.h"
+#include <pthread.h>
 
 pthread_mutex_t sbrk_mutex = PTHREAD_MUTEX_INITIALIZER;
 

block_header.h → private-include/block_header.h


+ 1 - 1
coalesce.h

@@ -1,7 +1,7 @@
 #ifndef COALESCE_H
 #define COALESCE_H
 
-#include "heap.h"
+#include <dmmlib/heap.h>
 
 /**
  * Merges a memory block with its previous one if the latter one is free.

+ 1 - 1
dmm_adaptor.h

@@ -1,4 +1,4 @@
-#include "heap.h"
+#include <dmmlib/heap.h>
 
 typedef uint8_t knob_state_t;
 

+ 1 - 1
dmm_init.h

@@ -1,7 +1,7 @@
 #ifndef DMM_INIT_H
 #define DMM_INIT_H
 
-#include "heap.h"
+#include <dmmlib/heap.h>
 
 void dmm_init(allocator_t *allocator);
 

+ 1 - 1
other.h

@@ -1,7 +1,7 @@
 #ifndef OTHER_H
 #define OTHER_H
 
-#include "heap.h"
+#include <dmmlib/heap.h>
 
 size_t req_padding(size_t size);
 

+ 1 - 1
posix_lock.h

@@ -1,7 +1,7 @@
 #ifndef POSIX_LOCK_H
 #define POSIX_LOCK_H
 
-#include "heap.h"
+#include <dmmlib/heap.h>
 
 void sbrk_lock(void);
 void sbrk_unlock(void);

sys_alloc.h → private-include/sys_alloc.h


+ 1 - 1
sys_alloc.c

@@ -2,6 +2,7 @@
 #include <stdio.h>
 #include <errno.h>
 #include <string.h>
+#include <dmmlib/heap.h>
 #include "dmm_config.h"
 #ifdef HAVE_LOCKS
 #include "posix_lock.h"
@@ -9,7 +10,6 @@
 #include "other.h"
 #include "sys_alloc.h"
 #include "block_header.h"
-#include "heap.h"
 
 void *sys_alloc(heap_t *heap, size_t size) {
     size_t allocation_size;