CringeDB/System Abstraction/win32/cdb_thread.c

31 lines
769 B
C
Raw Normal View History

2022-08-30 12:56:58 +02:00
#include "../cdb_sustem.h"
#include <windows.h>
2022-08-30 13:36:47 +02:00
struct threadInfo{
sus_threadProc proc;
void * args;
};
DWORD WINAPI threadProc(void * tiarg){
struct threadInfo * ti = tiarg;
struct threadInfo currentTI = {.args = ti->args, .proc = ti->proc};
sus_heapFree(ti);
2022-08-30 13:42:44 +02:00
currentTI.proc(currentTI.args);
return 0;
2022-08-30 12:56:58 +02:00
}
2022-08-30 13:36:47 +02:00
sus_Bool sus_threadNew(sus_threadProc proc, void * arg){
struct threadInfo * ti = sus_heapAlloc(sizeof(struct threadInfo));
ti->proc = proc;
ti->args = arg;
if(CreateThread(NULL, 0, threadProc, ti, 0, NULL) == NULL){
2022-08-30 13:47:12 +02:00
sus_heapFree(ti);
2022-08-30 12:56:58 +02:00
return sus_False;
}else{
return sus_True;
}
}
void sus_threadSleep(unsigned long seconds){
Sleep(seconds * 1000);
}