diff --git a/src/pthreads.c b/src/pthreads.c index 711dcbe..ea09e53 100644 --- a/src/pthreads.c +++ b/src/pthreads.c @@ -432,7 +432,7 @@ static uint32_t thread_wrap_up(struct pthreadpool* threadpool, return curr_active_threads; } -static void* thread_main(void* arg); +static pthreadpool_thread_return_t thread_main(void* arg); static void ensure_num_threads(struct pthreadpool* threadpool, uint32_t thread_id) { @@ -476,7 +476,7 @@ static void ensure_num_threads(struct pthreadpool* threadpool, } } -static void* thread_main(void* arg) { +static pthreadpool_thread_return_t thread_main(void* arg) { // Unpack the argument, i.e. extract the pointer to the `pthreadpool` from the // provided pointer to this thread's `thread_info`. struct thread_info* thread = (struct thread_info*)arg; @@ -558,7 +558,7 @@ static void* thread_main(void* arg) { // Release our hold on the threadpool. pthreadpool_release(threadpool); - return NULL; + return 0; } static size_t get_num_cpus() { diff --git a/src/threadpool-atomics.h b/src/threadpool-atomics.h index e27c59b..a90b6ff 100644 --- a/src/threadpool-atomics.h +++ b/src/threadpool-atomics.h @@ -56,6 +56,7 @@ typedef pthread_t pthreadpool_thread_t; typedef pthread_mutex_t pthreadpool_mutex_t; typedef pthread_cond_t pthreadpool_cond_t; +typedef void* pthreadpool_thread_return_t; static inline void pthreadpool_mutex_init(pthreadpool_mutex_t* mutex) { pthread_mutex_init(mutex, NULL); } @@ -84,18 +85,20 @@ static inline void pthreadpool_cond_signal(pthreadpool_cond_t* cond) { static inline void pthreadpool_cond_broadcast(pthreadpool_cond_t* cond) { pthread_cond_broadcast(cond); } -static inline void pthreadpool_thread_create(pthreadpool_thread_t* thread, - void*(fun)(void*), void* arg) { +static inline void pthreadpool_thread_create( + pthreadpool_thread_t* thread, pthreadpool_thread_return_t(fun)(void*), + void* arg) { pthread_create(thread, NULL, fun, arg); } -static inline void pthreadpool_thread_join(pthreadpool_thread_t thread, - void* return_value) { - pthread_join(thread, (void**)return_value); +static inline void pthreadpool_thread_join( + pthreadpool_thread_t thread, pthreadpool_thread_return_t* return_value) { + pthread_join(thread, return_value); } #else typedef thrd_t pthreadpool_thread_t; typedef mtx_t pthreadpool_mutex_t; typedef cnd_t pthreadpool_cond_t; +typedef int pthreadpool_thread_return_t; static inline void pthreadpool_mutex_init(pthreadpool_mutex_t* mutex) { mtx_init(mutex, mtx_plain); } @@ -124,12 +127,13 @@ static inline void pthreadpool_cond_signal(pthreadpool_cond_t* cond) { static inline void pthreadpool_cond_broadcast(pthreadpool_cond_t* cond) { cnd_broadcast(cond); } -static inline void pthreadpool_thread_create(pthreadpool_thread_t* thread, - void*(fun)(void*), void* arg) { +static inline void pthreadpool_thread_create( + pthreadpool_thread_t* thread, pthreadpool_thread_return_t(fun)(void*), + void* arg) { thrd_create(thread, fun, arg); } -static inline void pthreadpool_thread_join(pthreadpool_thread_t thread, - void* return_value) { +static inline void pthreadpool_thread_join( + pthreadpool_thread_t thread, pthreadpool_thread_return_t* return_value) { thrd_join(thread, return_value); } #endif // PTHREADPOOL_USE_PTHREADS