aboutsummaryrefslogtreecommitdiff
path: root/mutex.h
diff options
context:
space:
mode:
authorTest_User <hax@andrewyu.org>2024-06-20 18:29:24 -0400
committerTest_User <hax@andrewyu.org>2024-06-20 18:29:24 -0400
commitef6f87193ab6628a2366b004a21c5cb21304c663 (patch)
tree8406b6c90f6f4a65ac19360e4fbc640779b52aa5 /mutex.h
parent6a858830eb5ab1c8cd78e502471f88333b9bcca5 (diff)
downloadhaxircd-ef6f87193ab6628a2366b004a21c5cb21304c663.tar.gz
haxircd-ef6f87193ab6628a2366b004a21c5cb21304c663.zip
Seperate futex fom atomics
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) {