aboutsummaryrefslogtreecommitdiff
path: root/src/threading.cpp
diff options
context:
space:
mode:
authorSlendi <slendi@socopon.com>2024-02-15 15:51:28 +0200
committerSlendi <slendi@socopon.com>2024-02-15 15:51:28 +0200
commitc178f7199d7070c5481c5f0f3077f8dcbfa90226 (patch)
treefe181ee6187ca406fb8d5ed5ed55c3ae13ae840b /src/threading.cpp
parentc5c2a4d09d98f0d3b6263e204785553e47b83395 (diff)
Get Odin to compile on Haiku
This patch makes Odin to compile on Haiku which is a good first step. Now, all that's needed to do is to figure out how to do futexes, which I am blaming for the program crashing.
Diffstat (limited to 'src/threading.cpp')
-rw-r--r--src/threading.cpp47
1 files changed, 46 insertions, 1 deletions
diff --git a/src/threading.cpp b/src/threading.cpp
index 725b58c89..ea987890b 100644
--- a/src/threading.cpp
+++ b/src/threading.cpp
@@ -831,8 +831,53 @@ gb_internal void futex_wait(Futex *f, Footex val) {
WaitOnAddress(f, (void *)&val, sizeof(val), INFINITE);
} while (f->load() == val);
}
+#elif defined(GB_SYSTEM_HAIKU)
+
+#include <pthread.h>
+#include <unordered_map>
+#include <memory>
+
+struct MutexCond {
+ pthread_mutex_t mutex;
+ pthread_cond_t cond;
+};
+
+std::unordered_map<Futex*, std::unique_ptr<MutexCond>> futex_map;
+
+MutexCond* get_mutex_cond(Futex* f) {
+ if (futex_map.find(f) == futex_map.end()) {
+ futex_map[f] = std::make_unique<MutexCond>();
+ pthread_mutex_init(&futex_map[f]->mutex, NULL);
+ pthread_cond_init(&futex_map[f]->cond, NULL);
+ }
+ return futex_map[f].get();
+}
+
+void futex_signal(Futex *f) {
+ MutexCond* mc = get_mutex_cond(f);
+ pthread_mutex_lock(&mc->mutex);
+ pthread_cond_signal(&mc->cond);
+ pthread_mutex_unlock(&mc->mutex);
+}
+
+void futex_broadcast(Futex *f) {
+ MutexCond* mc = get_mutex_cond(f);
+ pthread_mutex_lock(&mc->mutex);
+ pthread_cond_broadcast(&mc->cond);
+ pthread_mutex_unlock(&mc->mutex);
+}
+
+void futex_wait(Futex *f, Footex val) {
+ MutexCond* mc = get_mutex_cond(f);
+ pthread_mutex_lock(&mc->mutex);
+ while (f->load() == val) {
+ pthread_cond_wait(&mc->cond, &mc->mutex);
+ }
+ pthread_mutex_unlock(&mc->mutex);
+}
+
#endif
#if defined(GB_SYSTEM_WINDOWS)
#pragma warning(pop)
-#endif \ No newline at end of file
+#endif