|
@@ -27,6 +27,8 @@
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
|
+#include "locks.h"
|
|
|
+
|
|
|
#ifdef BITMAP_RB_ONLY
|
|
|
#include "bitmap/bitmap.h"
|
|
|
#include "bitmap/bitmap_rb.h"
|
|
@@ -65,9 +67,7 @@ void * malloc(size_t size) {
|
|
|
/* Try to find a raw block available for allocation */
|
|
|
|
|
|
while(raw_block != NULL) {
|
|
|
-#ifdef HAVE_LOCKS
|
|
|
- pthread_mutex_lock(&raw_block->mutex);
|
|
|
-#endif /* HAVE_LOCKS */
|
|
|
+ lock_raw_block(raw_block);
|
|
|
encapsulated_rb =
|
|
|
#ifdef BITMAP_RB_ONLY
|
|
|
(bitmap_rb_t *)
|
|
@@ -77,9 +77,8 @@ void * malloc(size_t size) {
|
|
|
#endif /* FL_RB_ONLY */
|
|
|
((uintptr_t) raw_block + sizeof(raw_block_header_t));
|
|
|
ptr = dmmlib_malloc(encapsulated_rb, size);
|
|
|
-#ifdef HAVE_LOCKS
|
|
|
- pthread_mutex_unlock(&raw_block->mutex);
|
|
|
-#endif /* HAVE_LOCKS */
|
|
|
+ unlock_raw_block(raw_block);
|
|
|
+
|
|
|
if(ptr != NULL) {
|
|
|
break;
|
|
|
}
|
|
@@ -114,15 +113,11 @@ void * malloc(size_t size) {
|
|
|
/* When debugging is enabled, the big blocks are also stored on
|
|
|
* a list. */
|
|
|
#ifdef WITH_DEBUG
|
|
|
-#ifdef HAVE_LOCKS
|
|
|
- pthread_mutex_lock(&systemallocator.creation_mutex);
|
|
|
-#endif /* HAVE_LOCKS */
|
|
|
+ lock_global();
|
|
|
((raw_block_header_t *)ptr)->next_raw_block =
|
|
|
systemallocator.big_blocks_head;
|
|
|
systemallocator.big_blocks_head = (raw_block_header_t *)ptr;
|
|
|
-#ifdef HAVE_LOCKS
|
|
|
- pthread_mutex_unlock(&systemallocator.creation_mutex);
|
|
|
-#endif /* HAVE_LOCKS */
|
|
|
+ unlock_global();
|
|
|
#endif /* WITH_DEBUG */
|
|
|
|
|
|
#ifdef WITH_ALLOCATOR_STATS
|
|
@@ -139,9 +134,7 @@ void * malloc(size_t size) {
|
|
|
|
|
|
} else {
|
|
|
|
|
|
-#ifdef HAVE_LOCKS
|
|
|
- pthread_mutex_lock(&systemallocator.creation_mutex);
|
|
|
-#endif /* HAVE_LOCKS */
|
|
|
+ lock_global();
|
|
|
new_raw_block = create_raw_block((size_t) SYS_ALLOC_SIZE,
|
|
|
#ifdef FL_RB_ONLY
|
|
|
FREELIST
|
|
@@ -153,11 +146,9 @@ void * malloc(size_t size) {
|
|
|
if(new_raw_block != NULL) {
|
|
|
new_raw_block->next_raw_block = systemallocator.raw_block_head;
|
|
|
systemallocator.raw_block_head = new_raw_block;
|
|
|
-#ifdef HAVE_LOCKS
|
|
|
- pthread_mutex_unlock(&systemallocator.creation_mutex);
|
|
|
- pthread_mutex_lock(&new_raw_block->mutex);
|
|
|
-#endif /* HAVE_LOCKS */
|
|
|
+ unlock_global();
|
|
|
|
|
|
+ lock_raw_block(new_raw_block);
|
|
|
encapsulated_rb =
|
|
|
#ifdef BITMAP_RB_ONLY
|
|
|
(bitmap_rb_t *)
|
|
@@ -167,9 +158,7 @@ void * malloc(size_t size) {
|
|
|
#endif /* FL_RB_ONLY */
|
|
|
((uintptr_t) new_raw_block + sizeof(raw_block_header_t));
|
|
|
ptr = dmmlib_malloc(encapsulated_rb, size);
|
|
|
-#ifdef HAVE_LOCKS
|
|
|
- pthread_mutex_unlock(&new_raw_block->mutex);
|
|
|
-#endif /* HAVE_LOCKS */
|
|
|
+ unlock_raw_block(new_raw_block);
|
|
|
}
|
|
|
}
|
|
|
}
|