CringeDB/System Abstraction/win32/cdb_thread.c

31 lines
769 B
C
Raw Normal View History

2024-02-18 17:42:05 +01:00
#include "../cdb_system.h"
2022-08-30 12:56:58 +02:00
#include <windows.h>
2022-08-30 13:36:47 +02:00
struct threadInfo{
2024-02-18 17:42:05 +01:00
sys_threadProc proc;
2022-08-30 13:36:47 +02:00
void * args;
};
DWORD WINAPI threadProc(void * tiarg){
struct threadInfo * ti = tiarg;
struct threadInfo currentTI = {.args = ti->args, .proc = ti->proc};
2024-02-18 17:42:05 +01:00
sys_heapFree(ti);
2022-08-30 13:42:44 +02:00
currentTI.proc(currentTI.args);
return 0;
2022-08-30 12:56:58 +02:00
}
2024-02-18 17:42:05 +01:00
sys_Bool sys_threadNew(sys_threadProc proc, void * arg){
struct threadInfo * ti = sys_heapAlloc(sizeof(struct threadInfo));
2022-08-30 13:36:47 +02:00
ti->proc = proc;
ti->args = arg;
if(CreateThread(NULL, 0, threadProc, ti, 0, NULL) == NULL){
2024-02-18 17:42:05 +01:00
sys_heapFree(ti);
return sys_False;
2022-08-30 12:56:58 +02:00
}else{
2024-02-18 17:42:05 +01:00
return sys_True;
2022-08-30 12:56:58 +02:00
}
}
2024-02-18 17:42:05 +01:00
void sys_threadSleep(unsigned long seconds){
2022-08-30 12:56:58 +02:00
Sleep(seconds * 1000);
}