mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 16:18:52 +00:00
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:
@@ -83,6 +83,11 @@ OpenBSD)
|
||||
LDFLAGS="$LDFLAGS -liconv"
|
||||
LDFLAGS="$LDFLAGS $($LLVM_CONFIG --libs core native --system-libs)"
|
||||
;;
|
||||
Haiku)
|
||||
CXXFLAGS="$CXXFLAGS $($LLVM_CONFIG --cxxflags --ldflags) -I/system/develop/headers/private/shared -I/system/develop/headers/private/kernel"
|
||||
LDFLAGS="$LDFLAGS -liconv"
|
||||
LDFLAGS="$LDFLAGS $($LLVM_CONFIG --libs core native --system-libs)"
|
||||
;;
|
||||
*)
|
||||
error "Platform \"$OS_NAME\" unsupported"
|
||||
;;
|
||||
|
||||
+47
-2
@@ -83,6 +83,10 @@ extern "C" {
|
||||
#ifndef GB_SYSTEM_OPENBSD
|
||||
#define GB_SYSTEM_OPENBSD 1
|
||||
#endif
|
||||
#elif defined(__HAIKU__) || defined(__haiku__)
|
||||
#ifndef GB_SYSTEM_HAIKU
|
||||
#define GB_SYSTEM_HAIKU 1
|
||||
#endif
|
||||
#else
|
||||
#error This UNIX operating system is not supported
|
||||
#endif
|
||||
@@ -206,7 +210,7 @@ extern "C" {
|
||||
#endif
|
||||
#include <stdlib.h> // NOTE(bill): malloc on linux
|
||||
#include <sys/mman.h>
|
||||
#if !defined(GB_SYSTEM_OSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__)
|
||||
#if !defined(GB_SYSTEM_OSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__HAIKU__)
|
||||
#include <sys/sendfile.h>
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
@@ -248,6 +252,13 @@ extern "C" {
|
||||
#define lseek64 lseek
|
||||
#endif
|
||||
|
||||
#if defined(GB_SYSTEM_HAIKU)
|
||||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
#include <kernel/OS.h>
|
||||
#define lseek64 lseek
|
||||
#endif
|
||||
|
||||
#if defined(GB_SYSTEM_UNIX)
|
||||
#include <semaphore.h>
|
||||
#endif
|
||||
@@ -801,6 +812,13 @@ typedef struct gbAffinity {
|
||||
isize thread_count;
|
||||
isize threads_per_core;
|
||||
} gbAffinity;
|
||||
#elif defined(GB_SYSTEM_HAIKU)
|
||||
typedef struct gbAffinity {
|
||||
b32 is_accurate;
|
||||
isize core_count;
|
||||
isize thread_count;
|
||||
isize threads_per_core;
|
||||
} gbAffinity;
|
||||
#else
|
||||
#error TODO(bill): Unknown system
|
||||
#endif
|
||||
@@ -2984,6 +3002,8 @@ gb_inline u32 gb_thread_current_id(void) {
|
||||
__asm__("mov %%fs:0x10,%0" : "=r"(thread_id));
|
||||
#elif defined(GB_SYSTEM_LINUX)
|
||||
thread_id = gettid();
|
||||
#elif defined(GB_SYSTEM_HAIKU)
|
||||
thread_id = find_thread(NULL);
|
||||
#else
|
||||
#error Unsupported architecture for gb_thread_current_id()
|
||||
#endif
|
||||
@@ -3184,7 +3204,9 @@ b32 gb_affinity_set(gbAffinity *a, isize core, isize thread_index) {
|
||||
//info.affinity_tag = cast(integer_t)index;
|
||||
//result = thread_policy_set(thread, THREAD_AFFINITY_POLICY, cast(thread_policy_t)&info, THREAD_AFFINITY_POLICY_COUNT);
|
||||
|
||||
#if !defined(GB_SYSTEM_HAIKU)
|
||||
result = pthread_setaffinity_np(thread, sizeof(cpuset_t), &mn);
|
||||
#endif
|
||||
return result == 0;
|
||||
}
|
||||
|
||||
@@ -3236,6 +3258,29 @@ b32 gb_affinity_set(gbAffinity *a, isize core, isize thread_index) {
|
||||
return true;
|
||||
}
|
||||
|
||||
isize gb_affinity_thread_count_for_core(gbAffinity *a, isize core) {
|
||||
GB_ASSERT(0 <= core && core < a->core_count);
|
||||
return a->threads_per_core;
|
||||
}
|
||||
#elif defined(GB_SYSTEM_HAIKU)
|
||||
#include <unistd.h>
|
||||
|
||||
void gb_affinity_init(gbAffinity *a) {
|
||||
a->core_count = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
a->threads_per_core = 1;
|
||||
a->is_accurate = a->core_count > 0;
|
||||
a->core_count = a->is_accurate ? a->core_count : 1;
|
||||
a->thread_count = a->core_count;
|
||||
}
|
||||
|
||||
void gb_affinity_destroy(gbAffinity *a) {
|
||||
gb_unused(a);
|
||||
}
|
||||
|
||||
b32 gb_affinity_set(gbAffinity *a, isize core, isize thread_index) {
|
||||
return true;
|
||||
}
|
||||
|
||||
isize gb_affinity_thread_count_for_core(gbAffinity *a, isize core) {
|
||||
GB_ASSERT(0 <= core && core < a->core_count);
|
||||
return a->threads_per_core;
|
||||
@@ -5457,7 +5502,7 @@ gb_inline b32 gb_file_copy(char const *existing_filename, char const *new_filena
|
||||
}
|
||||
}
|
||||
|
||||
gb_free(buf);
|
||||
gb_mfree(buf);
|
||||
close(new_fd);
|
||||
close(existing_fd);
|
||||
|
||||
|
||||
+1
-1
@@ -341,7 +341,7 @@ gb_internal ReadDirectoryError read_directory(String path, Array<FileInfo> *fi)
|
||||
|
||||
return ReadDirectory_None;
|
||||
}
|
||||
#elif defined(GB_SYSTEM_LINUX) || defined(GB_SYSTEM_OSX) || defined(GB_SYSTEM_FREEBSD) || defined(GB_SYSTEM_OPENBSD)
|
||||
#elif defined(GB_SYSTEM_LINUX) || defined(GB_SYSTEM_OSX) || defined(GB_SYSTEM_FREEBSD) || defined(GB_SYSTEM_OPENBSD) || defined(GB_SYSTEM_HAIKU)
|
||||
|
||||
#include <dirent.h>
|
||||
|
||||
|
||||
@@ -831,6 +831,51 @@ 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)
|
||||
|
||||
Reference in New Issue
Block a user