瀏覽代碼

capitalize the lock macros

Ioannis Koutras 12 年之前
父節點
當前提交
9c496bf224
共有 13 個文件被更改,包括 62 次插入62 次删除
  1. 10 10
      private-include/locks.h
  2. 2 2
      src/bitmap/free.c
  3. 2 2
      src/bitmap/malloc.c
  4. 4 4
      src/bitmap/realloc.c
  5. 6 6
      src/free.c
  6. 6 6
      src/freelist/free.c
  7. 2 2
      src/freelist/malloc.c
  8. 2 2
      src/freelist/realloc.c
  9. 4 4
      src/knobs.c
  10. 9 9
      src/malloc.c
  11. 8 8
      src/memalign.c
  12. 3 3
      src/raw_block.c
  13. 4 4
      src/realloc.c

+ 10 - 10
private-include/locks.h

@@ -32,28 +32,28 @@
 #include <pthread.h>
 
 /** Locks the systemallocator object */
-#define lock_global() pthread_mutex_lock(&systemallocator.creation_mutex)
+#define LOCK_GLOBAL() pthread_mutex_lock(&systemallocator.creation_mutex)
 /** Unlocks the systemallocator object */
-#define unlock_global() pthread_mutex_unlock(&systemallocator.creation_mutex)
+#define UNLOCK_GLOBAL() pthread_mutex_unlock(&systemallocator.creation_mutex)
 /** Locks a specific raw block */
-#define lock_raw_block(rb) pthread_mutex_lock(&rb->mutex)
+#define LOCK_RAW_BLOCK(rb) pthread_mutex_lock(&rb->mutex)
 /** Initialized a raw block lock */
-#define init_raw_block_lock(rb) pthread_mutex_init(&rb->mutex, NULL);
+#define INIT_RAW_BLOCK_LOCK(rb) pthread_mutex_init(&rb->mutex, NULL);
 /** Unlocks a specific raw block */
-#define unlock_raw_block(rb) pthread_mutex_unlock(&rb->mutex)
+#define UNLOCK_RAW_BLOCK(rb) pthread_mutex_unlock(&rb->mutex)
 
 #else /* HAVE_LOCKS */
 
 /** Does nothing. */
-#define lock_global()
+#define LOCK_GLOBAL()
 /** Does nothing. */
-#define unlock_global()
+#define UNLOCK_GLOBAL()
 /** Does nothing. */
-#define lock_raw_block(rb)
+#define LOCK_RAW_BLOCK(RB)
 /** Does nothing. */
-#define init_raw_block_lock(rb)
+#define INIT_RAW_BLOCK_LOCK(RB)
 /** Does nothing. */
-#define unlock_raw_block(rb)
+#define UNLOCK_RAW_BLOCK(RB)
 
 #endif /* HAVE_LOCKS */
 

+ 2 - 2
src/bitmap/free.c

@@ -71,14 +71,14 @@ void bitmap_free(bitmap_rb_t *raw_block, void *ptr) {
     }
 
 #ifdef WITH_ALLOCATOR_STATS
-    lock_global();
+    LOCK_GLOBAL();
     update_stats(&systemallocator.dmm_stats,
             FREE,
 #ifdef REQUEST_SIZE_INFO
             chunk_header->requested_size,
 #endif /* REQUEST_SIZE_INFO */
             cells_used * raw_block->bytes_per_cell);
-    unlock_global();
+    UNLOCK_GLOBAL();
 #endif /* WITH_ALLOCATOR_STATS */
 
 }

+ 2 - 2
src/bitmap/malloc.c

@@ -125,14 +125,14 @@ void * bitmap_malloc(bitmap_rb_t *raw_block, size_t req_size) {
 
             // 5. Statistics support
 #ifdef WITH_ALLOCATOR_STATS
-            lock_global();
+            LOCK_GLOBAL();
             update_stats(&systemallocator.dmm_stats,
                     MALLOC,
 #ifdef REQUEST_SIZE_INFO
                     req_size - CHUNK_HDR_SIZE,
 #endif /* REQUEST_SIZE_INFO */
                     cells * raw_block->bytes_per_cell);
-            unlock_global();
+            UNLOCK_GLOBAL();
 #endif /* WITH_ALLOCATOR_STATS */
 
             break;

+ 4 - 4
src/bitmap/realloc.c

@@ -60,9 +60,9 @@ void * bitmap_realloc(bitmap_rb_t *raw_block, void * ptr,
 #endif /* HAVE_LOCKS */
 
         /* Try initially to allocate space from the same raw block */
-        lock_raw_block(rb);
+        LOCK_RAW_BLOCK(rb);
         ret = bitmap_malloc(raw_block, req_size);
-        unlock_raw_block(rb);
+        UNLOCK_RAW_BLOCK(rb);
 
         /* If no space can be found, try your luck in other raw blocks */
         if(ret == NULL) {
@@ -71,9 +71,9 @@ void * bitmap_realloc(bitmap_rb_t *raw_block, void * ptr,
 
         if(ret != NULL) {
             memcpy(ret, ptr, old_size);
-            lock_raw_block(rb);
+            LOCK_RAW_BLOCK(rb);
             bitmap_free(raw_block, ptr);
-            unlock_raw_block(rb);
+            UNLOCK_RAW_BLOCK(rb);
         }
     }
 

+ 6 - 6
src/free.c

@@ -60,30 +60,30 @@ void free(void *ptr) {
         DEFAULT_RB_T *encapsulated_rb = (DEFAULT_RB_T *)
             ((uintptr_t) owner_raw_block + sizeof(raw_block_header_t));
 
-        lock_raw_block(owner_raw_block);
+        LOCK_RAW_BLOCK(owner_raw_block);
         dmmlib_free(encapsulated_rb, ptr);
-        unlock_raw_block(owner_raw_block);
+        UNLOCK_RAW_BLOCK(owner_raw_block);
 
     } else { // It has to be a BIGBLOCK, just munmap it
         owner_raw_block = (raw_block_header_t *)
             ((uintptr_t) ptr - sizeof(raw_block_header_t));
 
 #ifdef WITH_DEBUG
-        lock_global();
+        LOCK_GLOBAL();
         SLIST_REMOVE(&systemallocator.bb_head, owner_raw_block,
                 raw_block_header_s, pointers);
-        unlock_global();
+        UNLOCK_GLOBAL();
 #endif /* WITH_DEBUG */
 
 #ifdef WITH_ALLOCATOR_STATS
-        lock_global();
+        LOCK_GLOBAL();
         update_stats(&systemallocator.dmm_stats,
                 FREE,
 #ifdef REQUEST_SIZE_INFO
                 owner_raw_block->requested_size,
 #endif /* REQUEST_SIZE_INFO */
                 owner_raw_block->size);
-        unlock_global();
+        UNLOCK_GLOBAL();
 #endif /* WITH_ALLOCATOR_STATS */
 
         /* release_memory(owner_raw_block); */

+ 6 - 6
src/freelist/free.c

@@ -49,14 +49,14 @@ void freelist_free(freelist_rb_t *raw_block, void *ptr) {
     // free neighbors.
 
 #ifdef WITH_ALLOCATOR_STATS
-            lock_global();
-            update_stats(&systemallocator.dmm_stats,
-                    FREE,
+    LOCK_GLOBAL();
+    update_stats(&systemallocator.dmm_stats,
+            FREE,
 #ifdef REQUEST_SIZE_INFO
-                    get_requested_size(block),
+            get_requested_size(block),
 #endif /* REQUEST_SIZE_INFO */
-                    get_size(block) + HEADER_SIZE);
-            unlock_global();
+            get_size(block) + HEADER_SIZE);
+    UNLOCK_GLOBAL();
 #endif /* WITH_ALLOCATOR_STATS */
 
 #if defined (COALESCING_FIXED) || defined (COALESCING_VARIABLE)

+ 2 - 2
src/freelist/malloc.c

@@ -123,14 +123,14 @@ void * freelist_malloc(freelist_rb_t *raw_block, size_t size) {
     if(ptr != NULL) {
 
 #ifdef WITH_ALLOCATOR_STATS
-        lock_global();
+        LOCK_GLOBAL();
         update_stats(&systemallocator.dmm_stats,
                 MALLOC,
 #ifdef REQUEST_SIZE_INFO
                 size,
 #endif /* REQUEST_SIZE_INFO */
                 get_size(ptr) + HEADER_SIZE);
-        unlock_global();
+        UNLOCK_GLOBAL();
 #endif /* WITH_ALLOCATOR_STATS */
 
         return (void *)((uintptr_t) ptr + HEADER_SIZE);

+ 2 - 2
src/freelist/realloc.c

@@ -77,8 +77,8 @@ void * freelist_realloc(freelist_rb_t *raw_block, void *ptr,
     rb = (raw_block_header_t *)
         ((uintptr_t) raw_block - sizeof(raw_block_header_t));
 #endif /* HAVE_LOCKS */
-    lock_raw_block(rb);
+    LOCK_RAW_BLOCK(rb);
     freelist_free(raw_block, ptr);
-    unlock_raw_block(rb);
+    UNLOCK_RAW_BLOCK(rb);
     return ret;
 }

+ 4 - 4
src/knobs.c

@@ -31,7 +31,7 @@ __attribute__((constructor)) void knobs_init(void);
 
 /** Initializes the knobs structure of the system allocator. */
 void knobs_init(void) {
-    lock_global();
+    LOCK_GLOBAL();
     systemallocator.dmm_knobs.sys_alloc_size = SYS_ALLOC_SIZE;
 #ifdef GOOD_FIT
     systemallocator.dmm_knobs.fitpercentage = GOOD_FIT_PERCENTAGE;
@@ -42,14 +42,14 @@ void knobs_init(void) {
 #ifdef SPLITTING_VARIABLE
     systemallocator.dmm_knobs.min_split_size = MIN_SPLITTING_SIZE;
 #endif /* SPLITTING_VARIABLE */
-    unlock_global();
+    UNLOCK_GLOBAL();
 }
 
 uint32_t dmm_set_knobs(dmm_knobs_t *conf);
 
 /** Sets the system allocator's knob structure. */
 uint32_t dmm_set_knobs(dmm_knobs_t *conf) {
-    lock_global();
+    LOCK_GLOBAL();
     systemallocator.dmm_knobs.sys_alloc_size = conf->sys_alloc_size;
 #ifdef GOOD_FIT
     systemallocator.dmm_knobs.fitpercentage = conf->fitpercentage;
@@ -60,6 +60,6 @@ uint32_t dmm_set_knobs(dmm_knobs_t *conf) {
 #ifdef SPLITTING_VARIABLE
     systemallocator.dmm_knobs.min_split_size = conf->min_split_size;
 #endif /* SPLITTING_VARIABLE */
-    unlock_global();
+    UNLOCK_GLOBAL();
     return 0;
 }

+ 9 - 9
src/malloc.c

@@ -57,11 +57,11 @@ void * malloc(size_t size) {
     /* Try to find a raw block available for allocation */
 
     SLIST_FOREACH(raw_block, &systemallocator.rb_head, pointers) {
-        lock_raw_block(raw_block);
+        LOCK_RAW_BLOCK(raw_block);
         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);
+        UNLOCK_RAW_BLOCK(raw_block);
 
         if(ptr != NULL) {
             /* Check that a valid pointer has been returned */
@@ -100,7 +100,7 @@ void * malloc(size_t size) {
                 sizeof(freelist_rb_t)) {
 #endif /* FL_RB_ONLY */
 
-            lock_global();
+            LOCK_GLOBAL();
             ptr = create_raw_block(size + sizeof(raw_block_header_t),
                         BIGBLOCK);
             if(ptr != NULL) {
@@ -119,29 +119,29 @@ void * malloc(size_t size) {
                         ((raw_block_header_t *)ptr)->size);
 #endif /* WITH_ALLOCATOR_STATS */
 
-                unlock_global();
+                UNLOCK_GLOBAL();
 
                 ptr = (void *)((uintptr_t) ptr + sizeof(raw_block_header_t));
             }
 
-            unlock_global();
+            UNLOCK_GLOBAL();
 
         } else {
             /* Try to create a new raw block and allocate a memory block from
              * there */
 
-            lock_global();
+            LOCK_GLOBAL();
             new_raw_block = create_raw_block((size_t) sys_alloc_size,
                     DEFAULT_RB_TYPE);
             if(new_raw_block != NULL) {
-                lock_raw_block(new_raw_block);
+                LOCK_RAW_BLOCK(new_raw_block);
                 SLIST_INSERT_HEAD(&systemallocator.rb_head, new_raw_block, pointers);
-                unlock_global();
+                UNLOCK_GLOBAL();
 
                 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);
+                UNLOCK_RAW_BLOCK(new_raw_block);
             }
         }
     }

+ 8 - 8
src/memalign.c

@@ -68,11 +68,11 @@ int posix_memalign(void **memptr, size_t alignment, size_t size) {
     /* Search the available freelist-organized raw blocks for a block whose size
      * is size + alignment - 1 */
     SLIST_FOREACH(raw_block, &systemallocator.rb_head, pointers) {
-        lock_raw_block(raw_block);
+        LOCK_RAW_BLOCK(raw_block);
         encapsulated_rb = (freelist_rb_t *) 
             ((uintptr_t) raw_block + sizeof(raw_block_header_t));
         *memptr = dmmlib_malloc(encapsulated_rb, size + alignment - 1);
-        unlock_raw_block(raw_block);
+        UNLOCK_RAW_BLOCK(raw_block);
 
 CheckAlignment:
 
@@ -162,10 +162,10 @@ CheckAlignment:
             if(*memptr != NULL) {
 
 #ifdef WITH_DEBUG
-                lock_global();
+                LOCK_GLOBAL();
                 SLIST_INSERT_HEAD(&systemallocator.bb_head,
                         (raw_block_header_t *) *memptr, pointers);
-                unlock_global();
+                UNLOCK_GLOBAL();
 #endif /* WITH_DEBUG */
 
 #ifdef WITH_ALLOCATOR_STATS
@@ -197,18 +197,18 @@ CheckAlignment:
                 }
             }
         } else { /* Create a new raw block and use it */
-            lock_global();
+            LOCK_GLOBAL();
             raw_block = create_raw_block((size_t) SYS_ALLOC_SIZE,
                     DEFAULT_RB_TYPE);
             if(raw_block != NULL) {
-                lock_raw_block(raw_block);
+                LOCK_RAW_BLOCK(raw_block);
                 SLIST_INSERT_HEAD(&systemallocator.rb_head, raw_block, pointers);
-                unlock_global();
+                UNLOCK_GLOBAL();
 
                 encapsulated_rb = (DEFAULT_RB_T *)
                     ((uintptr_t) raw_block + sizeof(raw_block_header_t));
                 *memptr = dmmlib_malloc(encapsulated_rb, size + alignment - 1);
-                unlock_raw_block(raw_block);
+                UNLOCK_RAW_BLOCK(raw_block);
 
                 if(*memptr != NULL) {
                     goto CheckAlignment;

+ 3 - 3
src/raw_block.c

@@ -56,8 +56,8 @@ raw_block_header_t *create_raw_block(size_t raw_block_size, rb_type type) {
         return NULL;
     }
 
-    init_raw_block_lock(ptr);
-    lock_raw_block(ptr);
+    INIT_RAW_BLOCK_LOCK(ptr);
+    LOCK_RAW_BLOCK(ptr);
 
 #ifdef REQUEST_SIZE_INFO
     ptr->requested_size = raw_block_size;
@@ -127,7 +127,7 @@ raw_block_header_t *create_raw_block(size_t raw_block_size, rb_type type) {
             break;
     }
 
-    unlock_raw_block(ptr);
+    UNLOCK_RAW_BLOCK(ptr);
 
     return ptr;
 }

+ 4 - 4
src/realloc.c

@@ -125,18 +125,18 @@ void * realloc(void *ptr, size_t size) {
                         owner_raw_block->size - sizeof(raw_block_header_t));
 
 #ifdef WITH_DEBUG
-                lock_global();
+                LOCK_GLOBAL();
                 SLIST_REMOVE(&systemallocator.bb_head, owner_raw_block,
                         raw_block_header_s, pointers);
                 SLIST_INSERT_HEAD(&systemallocator.bb_head,
                         new_block, pointers);
-                unlock_global();
+                UNLOCK_GLOBAL();
 #endif /* WITH_DEBUG */
 
                 release_memory(owner_raw_block);
 
 #ifdef WITH_ALLOCATOR_STATS
-                lock_global();
+                LOCK_GLOBAL();
                 systemallocator.dmm_stats.total_mem_allocated +=
                     size_diff;
                 TRACE_2("dmmlib - ms all %zu\n",
@@ -148,7 +148,7 @@ void * realloc(void *ptr, size_t size) {
                         systemallocator.dmm_stats.total_mem_requested);
 #endif /* REQUEST_SIZE_INFO */
                 systemallocator.dmm_stats.num_realloc++;
-                unlock_global();
+                UNLOCK_GLOBAL();
 #endif /* WITH_ALLOCATOR_STATS */
 
                 goto done;