Procházet zdrojové kódy

Conditional compilation of POSIX lock functions by using the HAVE_LOCKS flag.

Ioannis Koutras před 13 roky
rodič
revize
9c0daa3f0d
6 změnil soubory, kde provedl 31 přidání a 1 odebrání
  1. 7 1
      custom_free.c
  2. 8 0
      custom_malloc.c
  3. 4 0
      dmm_init.c
  4. 4 0
      heap.h
  5. 2 0
      posix_lock.c
  6. 6 0
      sys_alloc.c

+ 7 - 1
custom_free.c

@@ -1,6 +1,8 @@
 #include "custom_free.h"
 #include "other.h"
+#ifdef HAVE_LOCKS
 #include "posix_lock.h"
+#endif /* HAVE_LOCKS */
 #include "block_header.h"
 
 void custom_free(heap_t* heap, void *ptr) {
@@ -10,8 +12,10 @@ void custom_free(heap_t* heap, void *ptr) {
 
 	size = get_size(ptr);
 	fixed_list_id = map_size_to_list(heap, size);
-	
+
+#ifdef HAVE_LOCKS	
 	posix_lock(heap);
+#endif /* HAVE_LOCKS */
 
 	if(fixed_list_id != -1) {
 		current_maptable_node = heap->maptable_head;		
@@ -37,6 +41,8 @@ void custom_free(heap_t* heap, void *ptr) {
 
 	// End of Stats
 
+#ifdef HAVE_LOCKS
 	posix_unlock(heap);
+#endif /* HAVE_LOCKS */
 }
 

+ 8 - 0
custom_malloc.c

@@ -1,5 +1,7 @@
 #include "custom_malloc.h"
+#ifdef HAVE_LOCKS
 #include "posix_lock.h"
+#endif /* HAVE_LOCKS */
 #include "other.h"
 #include "sys_alloc.h"
 #include "block_header.h"
@@ -14,7 +16,9 @@ void * custom_malloc(heap_t* heap, size_t size) {
 	ptr = NULL;
 	previous_block = NULL;
 
+#ifdef HAVE_LOCKS
 	posix_lock(heap);
+#endif /* HAVE_LOCKS */
 
 	fixed_list_id = map_size_to_list(heap, size);
 	
@@ -60,7 +64,9 @@ void * custom_malloc(heap_t* heap, size_t size) {
 
 				// End of Stats
 
+#ifdef HAVE_LOCKS
 				posix_unlock(heap);
+#endif /* HAVE_LOCKS */
 				return ptr;
 			}
 			previous_block = current_block;
@@ -88,7 +94,9 @@ void * custom_malloc(heap_t* heap, size_t size) {
 		state_refresh(heap);
 	}
 
+#ifdef HAVE_LOCKS
 	posix_unlock(heap);
+#endif /* HAVE_LOCKS */
 	return ptr;
 }
 

+ 4 - 0
dmm_init.c

@@ -1,6 +1,8 @@
 #define _BSD_SOURCE
 #include <unistd.h>
+#ifdef HAVE_LOCKS
 #include <pthread.h>
+#endif /* HAVE_LOCKS */
 #include "dmm_init.h"
 
 allocator_t * dmm_init(void) {
@@ -30,7 +32,9 @@ allocator_t * dmm_init(void) {
 		main_allocator->heaps[i].dmm_knobs.frag_threshold = 1.0;
 		main_allocator->heaps[i].dmm_knobs.mem_threshold = 17000;
 
+#ifdef HAVE_LOCKS
 		pthread_mutex_init(&main_allocator->heaps[i].mutex, NULL);
+#endif /* HAVE_LOCKS */
 	}
 
 	// Custom number of fixed lists and their initialization

+ 4 - 0
heap.h

@@ -2,7 +2,9 @@
 #define HEAP_H
 
 #include <stdint.h>
+#ifdef HAVE_LOCKS
 #include <pthread.h>
+#endif /* HAVE_LOCKS */
 
 #include "block_header.h"
 
@@ -53,7 +55,9 @@ typedef struct heap_s {
 	uint64_t num_objects;
 	dmmstats_t dmm_stats;
 	dmmknobs_t dmm_knobs;
+#ifdef HAVE_LOCKS
 	pthread_mutex_t mutex;
+#endif /* HAVE_LOCKS */
 } heap_t;
 
 typedef struct allocator_s {

+ 2 - 0
posix_lock.c

@@ -1,3 +1,4 @@
+#ifdef HAVE_LOCKS
 #include <pthread.h>
 #include "posix_lock.h"
 
@@ -18,3 +19,4 @@ void posix_lock(heap_t *heap) {
 void posix_unlock(heap_t *heap) {
 	pthread_mutex_unlock(&heap->mutex);
 }
+#endif /* HAVE_LOCKS */

+ 6 - 0
sys_alloc.c

@@ -2,7 +2,9 @@
 #include <stdio.h>
 #include <errno.h>
 #include <string.h>
+#ifdef HAVE_LOCKS
 #include "posix_lock.h"
+#endif /* HAVE_LOCKS */
 #include "other.h"
 #include "sys_alloc.h"
 #include "block_header.h"
@@ -12,7 +14,9 @@ void *sys_alloc(heap_t *heap, size_t size) {
 	size_t allocation_size;
 	void *ptr;
 
+#ifdef HAVE_LOCKS
 	sbrk_lock();
+#endif /* HAVE_LOCKS */
 
 	allocation_size = req_padding(size) + HEADER_SIZE;
 
@@ -28,7 +32,9 @@ void *sys_alloc(heap_t *heap, size_t size) {
 	set_next(ptr, heap->used_blocks_head);	
 	heap->used_blocks_head = ptr;
 
+#ifdef HAVE_LOCKS
 	sbrk_unlock();
+#endif /* HAVE_LOCKS */
 
 	return  ptr;
 }