GoldFish Engine
Quite simple and lightweight game engine
Loading...
Searching...
No Matches
gf_thread.c
1
#define GF_EXPOSE_THREAD
2
3
#include <
gf_pre.h
>
4
5
/* External library */
6
#include <windows.h>
7
8
/* Interface */
9
#include <
gf_thread.h
>
10
11
/* Engine */
12
13
/* Standard */
14
#include <stdlib.h>
15
16
DWORD WINAPI gf_wrap_thread(
void
* arg) {
17
gf_thread_context_t
* ctx = (
gf_thread_context_t
*)arg;
18
ctx->
func
(ctx->
data
);
19
return
0;
20
}
21
22
gf_thread_t
*
gf_thread_create
(
void
(*func)(
void
*),
void
* userdata) {
23
gf_thread_t
* thread = malloc(
sizeof
(*thread));
24
thread->context.func = func;
25
thread->context.data = userdata;
26
if
((thread->thread = CreateThread(NULL, 0, gf_wrap_thread, &thread->context, 0, NULL)) != NULL)
return
thread;
27
free(thread);
28
return
NULL;
29
}
30
31
void
gf_thread_join
(
gf_thread_t
* thread) { WaitForSingleObject(thread->thread, INFINITE); }
32
33
void
gf_thread_destroy
(
gf_thread_t
* thread) {
34
CloseHandle(thread->thread);
35
free(thread);
36
}
gf_pre.h
Required headers before anything.
gf_thread.h
Thread interface.
gf_thread_join
void gf_thread_join(gf_thread_t *thread)
Join thread.
Definition
gf_thread.c:31
gf_thread_create
gf_thread_t * gf_thread_create(void(*func)(void *), void *userdata)
Create thread.
Definition
gf_thread.c:22
gf_thread_destroy
void gf_thread_destroy(gf_thread_t *thread)
Destroy thread.
Definition
gf_thread.c:36
gf_thread_context_t
Thread context.
Definition
thread.h:42
gf_thread_context_t::data
void * data
Data to be passed to thread.
Definition
thread.h:42
gf_thread_context_t::func
void(* func)(void *)
Function to be called for thread.
Definition
thread.h:42
gf_thread_t
Platform-dependent thread.
Definition
thread.h:61
src
thread
win32
gf_thread.c
Generated by
1.9.8