aboutsummaryrefslogtreecommitdiff
path: root/mutex.h
diff options
context:
space:
mode:
Diffstat (limited to 'mutex.h')
-rw-r--r--mutex.h10
1 files changed, 7 insertions, 3 deletions
diff --git a/mutex.h b/mutex.h
index 4e42dab..fd513eb 100644
--- a/mutex.h
+++ b/mutex.h
@@ -42,11 +42,15 @@ inline int mutex_init(uint32_t *futex) {
}
inline void mutex_lock(uint32_t *futex) {
- if (__sync_fetch_and_or(futex, 0x1) == 0)
- return;
+ do {
+ if (__sync_fetch_and_or(futex, 0x1) == 0)
+ return;
+
+ if (__sync_fetch_and_or(futex, 0x3) == 0)
+ return;
- while (__sync_fetch_and_or(futex, 0x3) != 0)
syscall(SYS_futex, futex, FUTEX_PRIVATE_FLAG | FUTEX_WAIT, 3, 0, 0, 0);
+ } while (1);
}
inline void mutex_unlock(uint32_t *futex) {