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.
This commit is contained in:
Slendi
2024-02-15 15:51:28 +02:00
parent c5c2a4d09d
commit c178f7199d
4 changed files with 559 additions and 464 deletions

View File

@@ -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
#endif