From c178f7199d7070c5481c5f0f3077f8dcbfa90226 Mon Sep 17 00:00:00 2001 From: Slendi Date: Thu, 15 Feb 2024 15:51:28 +0200 Subject: 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. --- src/threading.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'src/threading.cpp') 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 +#include +#include + +struct MutexCond { + pthread_mutex_t mutex; + pthread_cond_t cond; +}; + +std::unordered_map> futex_map; + +MutexCond* get_mutex_cond(Futex* f) { + if (futex_map.find(f) == futex_map.end()) { + futex_map[f] = std::make_unique(); + 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 -- cgit v1.2.3