mirror of
https://github.com/nishiowo/nishbox
synced 2025-04-21 20:24:39 +00:00
add more funcs
This commit is contained in:
parent
c22fd58f2e
commit
f17bc06b00
@ -12,5 +12,7 @@
|
||||
/* Standard */
|
||||
|
||||
nb_thread_t* nb_create_thread(void (*func)(void*), void* userdata);
|
||||
void nb_join_thread(nb_thread_t* thread);
|
||||
void nb_destroy_thread(nb_thread_t* thread);
|
||||
|
||||
#endif
|
||||
|
@ -27,3 +27,10 @@ nb_thread_t* nb_create_thread(void (*func)(void*), void* userdata) {
|
||||
free(thread);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void nb_join_thread(nb_thread_t* thread) {
|
||||
void* value;
|
||||
pthread_join(thread->thread, &value);
|
||||
}
|
||||
|
||||
void nb_destroy_thread(nb_thread_t* thread) { free(thread); }
|
||||
|
@ -23,9 +23,18 @@ nb_thread_t* nb_create_thread(void (*func)(void*), void* userdata) {
|
||||
nb_thread_t* thread = malloc(sizeof(*thread));
|
||||
thread->context.func = func;
|
||||
thread->context.data = userdata;
|
||||
if((thread->thread = CreateThread(NULL, 0, nb_wrap_thread, &thread->context, 0, NULL)) != NULL) return thread;
|
||||
/* XXX: Is this needed? */
|
||||
ResumeThread(thread->thread);
|
||||
if((thread->thread = CreateThread(NULL, 0, nb_wrap_thread, &thread->context, 0, NULL)) != NULL) {
|
||||
/* XXX: Is this needed? */
|
||||
ResumeThread(thread->thread);
|
||||
return thread;
|
||||
}
|
||||
free(thread);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void nb_join_thread(nb_thread_t* thread) { WaitForSingleObject(thread->thread, INFINITE); }
|
||||
|
||||
void nb_destroy_thread(nb_thread_t* thread) {
|
||||
CloseHandle(thread->thread);
|
||||
free(thread);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user