CringeDB/System Abstraction/linux/cdb_thread.c
MrLetsplay2003 6eca5c2af5 Linsus threads
Co-authored-by: Julian; <JDobeshow@users.noreply.github.com>
2022-08-30 13:47:02 +02:00

38 lines
894 B
C

#include "../cdb_sustem.h"
#include <pthread.h>
#include <unistd.h>
struct sus_thread_args {
sus_threadProc proc;
void *arg;
};
typedef struct sus_thread_args sus_thread_args;
// Linux only uses System V AMD64 ABI calling convention (source: https://en.wikipedia.org/wiki/X86_calling_conventions)
void *uwu_runThread(void *arg) {
sus_thread_args *args = (sus_thread_args *) arg;
sus_threadProc proc = args->proc;
void *arg2 = args->arg;
sus_heapFree(args);
proc(arg2);
return NULL;
}
sus_Bool sus_threadNew(sus_threadProc proc, void *arg) {
sus_thread_args *args = (sus_thread_args *) sus_heapAlloc(sizeof(sus_thread_args));
args->proc = proc;
args->arg = arg;
pthread_t thread;
if(pthread_create(&thread, NULL, uwu_runThread, args)) {
sus_heapFree(args);
return sus_False;
}else {
return sus_True;
}
}
void sus_threadSleep(unsigned long seconds) {
sleep(seconds);
}