aboutsummaryrefslogtreecommitdiff
path: root/mutex.h
diff options
context:
space:
mode:
authorTest_User <hax@andrewyu.org>2024-07-19 23:26:45 -0400
committerTest_User <hax@andrewyu.org>2024-07-19 23:26:45 -0400
commit59a07e28c5ef018d0c5cecd12d52ff10f5dc5b1a (patch)
tree5ca0a30a2426d5e6ba72ae61ad3c0e2f52cdd6cd /mutex.h
parente755e8b341eea1b37ef82584cd65a05edf8fdbaa (diff)
downloadhaxircd-59a07e28c5ef018d0c5cecd12d52ff10f5dc5b1a.tar.gz
haxircd-59a07e28c5ef018d0c5cecd12d52ff10f5dc5b1a.zip
Minimal support for non-semaphore-supporting systems
Diffstat (limited to 'mutex.h')
-rw-r--r--mutex.h22
1 files changed, 21 insertions, 1 deletions
diff --git a/mutex.h b/mutex.h
index a341152..7d1b4b2 100644
--- a/mutex.h
+++ b/mutex.h
@@ -26,7 +26,7 @@
#pragma once
-#ifdef USE_FUTEX
+#if defined(USE_FUTEX)
#include <unistd.h>
#include <sys/syscall.h>
@@ -61,6 +61,26 @@ inline void mutex_destroy(uint32_t *futex) {
return;
}
+#elif defined(USE_MISERABLE_SPINLOCKS)
+
+#define MUTEX_TYPE char
+
+inline void mutex_init(char *lock) {
+ *lock = 0;
+}
+
+inline void mutex_lock(char *lock) {
+ while (__sync_lock_test_and_set(lock, 0x1));
+}
+
+inline void mutex_unlock(char *lock) {
+ __sync_lock_release(lock);
+}
+
+inline void mutex_destroy(char *lock) {
+ return;
+}
+
#else
#include <semaphore.h>