restore lock-skipping for processes that return to single-threaded state
[musl] / src / malloc / malloc.c
index d72883e..a803d4c 100644 (file)
@@ -26,8 +26,11 @@ int __malloc_replaced;
 
 static inline void lock(volatile int *lk)
 {
-       if (libc.threads_minus_1)
+       int need_locks = libc.need_locks;
+       if (need_locks) {
                while(a_swap(lk, 1)) __wait(lk, lk+1, 1, 1);
+               if (need_locks < 0) libc.need_locks = 0;
+       }
 }
 
 static inline void unlock(volatile int *lk)
@@ -123,8 +126,6 @@ void __dump_heap(int x)
 }
 #endif
 
-void *__expand_heap(size_t *);
-
 static struct chunk *expand_heap(size_t n)
 {
        static int heap_lock[2];