Browse Source

apply trylock option for memalign() too

Ioannis Koutras 11 years ago
parent
commit
2a0f49b01a
1 changed files with 12 additions and 5 deletions
  1. 12 5
      src/memalign.c

+ 12 - 5
src/memalign.c

@@ -59,11 +59,18 @@ void *memalign(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);
-        encapsulated_rb = (freelist_rb_t *)
-            ((uintptr_t) raw_block + sizeof(raw_block_header_t));
-        memptr = freelist_memalign(encapsulated_rb, alignment, size);
-        UNLOCK_RAW_BLOCK(raw_block);
+#ifdef TRYLOCK_ON_MALLOC
+        if(TRYLOCK_RAW_BLOCK(raw_block) == 0) {
+#else /* TRYLOCK_ON_MALLOC */
+            LOCK_RAW_BLOCK(raw_block);
+#endif /* TRYLOCK_ON_MALLOC */
+            encapsulated_rb = (freelist_rb_t *)
+                ((uintptr_t) raw_block + sizeof(raw_block_header_t));
+            memptr = freelist_memalign(encapsulated_rb, alignment, size);
+            UNLOCK_RAW_BLOCK(raw_block);
+#ifdef TRYLOCK_ON_MALLOC
+        }
+#endif /* TRYLOCK_ON_MALLOC */
     }
 
     if(memptr == NULL) {