mirror of
https://github.com/nishiowo/nishbox
synced 2025-04-21 20:24:39 +00:00
37 lines
867 B
C
37 lines
867 B
C
#define GF_EXPOSE_THREAD
|
|
|
|
#include <gf_pre.h>
|
|
|
|
/* External library */
|
|
#include <windows.h>
|
|
|
|
/* Interface */
|
|
#include <gf_thread.h>
|
|
|
|
/* Engine */
|
|
|
|
/* Standard */
|
|
#include <stdlib.h>
|
|
|
|
GF_EXPORT DWORD WINAPI gf_wrap_thread(void* arg) {
|
|
gf_thread_context_t* ctx = (gf_thread_context_t*)arg;
|
|
ctx->func(ctx->data);
|
|
return 0;
|
|
}
|
|
|
|
GF_EXPORT gf_thread_t* gf_create_thread(void (*func)(void*), void* userdata) {
|
|
gf_thread_t* thread = malloc(sizeof(*thread));
|
|
thread->context.func = func;
|
|
thread->context.data = userdata;
|
|
if((thread->thread = CreateThread(NULL, 0, gf_wrap_thread, &thread->context, 0, NULL)) != NULL) return thread;
|
|
free(thread);
|
|
return NULL;
|
|
}
|
|
|
|
GF_EXPORT void gf_join_thread(gf_thread_t* thread) { WaitForSingleObject(thread->thread, INFINITE); }
|
|
|
|
GF_EXPORT void gf_destroy_thread(gf_thread_t* thread) {
|
|
CloseHandle(thread->thread);
|
|
free(thread);
|
|
}
|