base layer, mostly stolen

This commit is contained in:
Tenari
2026-04-04 09:15:37 -05:00
commit 42085666e9
18 changed files with 2528 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
#include "all.h"
Thread spawnThread(void * (*threadFn)(void *), void* thread_arg) {
pthread_t thread;
pthread_create(&thread, NULL, threadFn, thread_arg);
Thread result = { thread };
return result;
}
Mutex newMutex() {
Mutex result = { PTHREAD_MUTEX_INITIALIZER };
return result;
}
Cond newCond() {
Cond result = { 0 };
pthread_cond_init(&result.cond, NULL);
return result;
}
void lockMutex(Mutex* m) {
pthread_mutex_lock(&m->mutex);
}
void unlockMutex(Mutex* m) {
pthread_mutex_unlock(&m->mutex);
}
void signalCond(Cond* cond) {
pthread_cond_signal(&cond->cond);
}
void waitForCondSignal(Cond* cond, Mutex* mutex) {
pthread_cond_wait(&cond->cond, &mutex->mutex);
}