about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/internal/libc.h4
-rw-r--r--src/malloc/malloc.c15
-rw-r--r--src/thread/__lock.c9
3 files changed, 15 insertions, 13 deletions
diff --git a/src/internal/libc.h b/src/internal/libc.h
index 3350b3d1..d625b56a 100644
--- a/src/internal/libc.h
+++ b/src/internal/libc.h
@@ -53,8 +53,8 @@ void __lock(volatile int *) ATTR_LIBC_VISIBILITY;
 void __unlock(volatile int *) ATTR_LIBC_VISIBILITY;
 int __lockfile(FILE *) ATTR_LIBC_VISIBILITY;
 void __unlockfile(FILE *) ATTR_LIBC_VISIBILITY;
-#define LOCK(x) (libc.threads_minus_1 ? (__lock(x),1) : ((void)(x),1))
-#define UNLOCK(x) (libc.threads_minus_1 ? (__unlock(x),1) : ((void)(x),1))
+#define LOCK(x) __lock(x)
+#define UNLOCK(x) __unlock(x)
 
 void __synccall(void (*)(void *), void *);
 int __setxid(int, int, int, int);
diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c
index 4044eb2a..fb65ab5b 100644
--- a/src/malloc/malloc.c
+++ b/src/malloc/malloc.c
@@ -64,28 +64,27 @@ static struct {
 
 static inline void lock(volatile int *lk)
 {
-	if (!libc.threads_minus_1) return;
-	while(a_swap(lk, 1)) __wait(lk, lk+1, 1, 1);
+	if (libc.threads_minus_1)
+		while(a_swap(lk, 1)) __wait(lk, lk+1, 1, 1);
 }
 
 static inline void unlock(volatile int *lk)
 {
-	if (!libc.threads_minus_1) return;
-	a_store(lk, 0);
-	if (lk[1]) __wake(lk, 1, 1);
+	if (lk[0]) {
+		a_store(lk, 0);
+		if (lk[1]) __wake(lk, 1, 1);
+	}
 }
 
 static inline void lock_bin(int i)
 {
-	if (libc.threads_minus_1)
-		lock(mal.bins[i].lock);
+	lock(mal.bins[i].lock);
 	if (!mal.bins[i].head)
 		mal.bins[i].head = mal.bins[i].tail = BIN_TO_CHUNK(i);
 }
 
 static inline void unlock_bin(int i)
 {
-	if (!libc.threads_minus_1) return;
 	unlock(mal.bins[i].lock);
 }
 
diff --git a/src/thread/__lock.c b/src/thread/__lock.c
index 2f345ae7..0874c04a 100644
--- a/src/thread/__lock.c
+++ b/src/thread/__lock.c
@@ -2,11 +2,14 @@
 
 void __lock(volatile int *l)
 {
-	while (a_swap(l, 1)) __wait(l, l+1, 1, 1);
+	if (libc.threads_minus_1)
+		while (a_swap(l, 1)) __wait(l, l+1, 1, 1);
 }
 
 void __unlock(volatile int *l)
 {
-	a_store(l, 0);
-	if (l[1]) __wake(l, 1, 1);
+	if (l[0]) {
+		a_store(l, 0);
+		if (l[1]) __wake(l, 1, 1);
+	}
 }