add more funcs

This commit is contained in:
NishiOwO 2025-04-07 18:28:54 +09:00
parent c22fd58f2e
commit f17bc06b00
No known key found for this signature in database
GPG Key ID: 27EF69B208EB9343
3 changed files with 21 additions and 3 deletions

View File

@ -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

View File

@ -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); }

View File

@ -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);
}