diff options
author | Test_User <hax@andrewyu.org> | 2024-06-20 05:49:57 -0400 |
---|---|---|
committer | Test_User <hax@andrewyu.org> | 2024-06-20 05:49:57 -0400 |
commit | 3378539884a8cec2ba7b0c0d9237390842cd30e1 (patch) | |
tree | 4cd1188ec7259127fef6bc85452dfd075a97a64d /mutex.h | |
parent | ea4d0f1360c2c23764decea94efcc38a8e47cafb (diff) | |
download | haxircd-3378539884a8cec2ba7b0c0d9237390842cd30e1.tar.gz haxircd-3378539884a8cec2ba7b0c0d9237390842cd30e1.zip |
Only syscall to wake if there's one to be woken
Diffstat (limited to 'mutex.h')
-rw-r--r-- | mutex.h | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -42,14 +42,16 @@ inline int mutex_init(uint32_t *futex) { } inline void mutex_lock(uint32_t *futex) { - uint32_t val; - while ((val = __sync_lock_test_and_set(futex, 1))) - syscall(SYS_futex, futex, FUTEX_PRIVATE_FLAG | FUTEX_WAIT, val, 0, 0, 0); + if (__sync_fetch_and_or(futex, 0x1) == 0) + return; + + while (__sync_fetch_and_or(futex, 0x3) != 0) + syscall(SYS_futex, futex, FUTEX_PRIVATE_FLAG | FUTEX_WAIT, 3, 0, 0, 0); } inline void mutex_unlock(uint32_t *futex) { - __sync_lock_release(futex); - syscall(SYS_futex, futex, FUTEX_PRIVATE_FLAG | FUTEX_WAKE, 1, 0, 0, 0); + if (__sync_fetch_and_and(futex, 0) & 0x2) + syscall(SYS_futex, futex, FUTEX_PRIVATE_FLAG | FUTEX_WAKE, 1, 0, 0, 0); } inline void mutex_destroy(uint32_t *futex) { |