about summary refs log tree commit diff
path: root/src/malloc/malloc.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2012-09-14 23:52:51 -0400
committerRich Felker <dalias@aerifal.cx>2012-09-14 23:52:51 -0400
commitafd209deb7d3bfc9cc31713e2cb8f22693ca6fae (patch)
tree1988e392e57f4598e1a6371ea40162eaf7804f44 /src/malloc/malloc.c
parent9f74574fe697f0908d766579e73d94fc621463d4 (diff)
downloadmusl-afd209deb7d3bfc9cc31713e2cb8f22693ca6fae.tar.gz
musl-afd209deb7d3bfc9cc31713e2cb8f22693ca6fae.tar.xz
musl-afd209deb7d3bfc9cc31713e2cb8f22693ca6fae.zip
workaround gcc got-register-reload performance problems in malloc
with this patch, the malloc in libc.so built with -Os is nearly the
same speed as the one built with -O3. thus it solves the performance
regression that resulted from removing the forced -O3 when building
libc.so; now libc.so can be both small and fast.
Diffstat (limited to 'src/malloc/malloc.c')
-rw-r--r--src/malloc/malloc.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c
index 39c7d051..88a31ae4 100644
--- a/src/malloc/malloc.c
+++ b/src/malloc/malloc.c
@@ -9,6 +9,10 @@
 #include "atomic.h"
 #include "pthread_impl.h"
 
+#if defined(__GNUC__) && defined(__PIC__)
+#define inline inline __attribute__((always_inline))
+#endif
+
 uintptr_t __brk(uintptr_t);
 void *__mmap(void *, size_t, int, int, int, off_t);
 int __munmap(void *, size_t);
@@ -58,20 +62,20 @@ static struct {
 
 /* Synchronization tools */
 
-static void lock(volatile int *lk)
+static inline void lock(volatile int *lk)
 {
 	if (!libc.threads_minus_1) return;
 	while(a_swap(lk, 1)) __wait(lk, lk+1, 1, 1);
 }
 
-static void unlock(volatile int *lk)
+static inline void unlock(volatile int *lk)
 {
 	if (!libc.threads_minus_1) return;
 	a_store(lk, 0);
 	if (lk[1]) __wake(lk, 1, 1);
 }
 
-static void lock_bin(int i)
+static inline void lock_bin(int i)
 {
 	if (libc.threads_minus_1)
 		lock(mal.bins[i].lock);
@@ -79,7 +83,7 @@ static void lock_bin(int i)
 		mal.bins[i].head = mal.bins[i].tail = BIN_TO_CHUNK(i);
 }
 
-static void unlock_bin(int i)
+static inline void unlock_bin(int i)
 {
 	if (!libc.threads_minus_1) return;
 	unlock(mal.bins[i].lock);