diff options
-rw-r--r-- | lib/qpthreads.c | 28 | ||||
-rw-r--r-- | lib/qpthreads.h | 3 |
2 files changed, 31 insertions, 0 deletions
diff --git a/lib/qpthreads.c b/lib/qpthreads.c index e7a8da2f..ba6e20be 100644 --- a/lib/qpthreads.c +++ b/lib/qpthreads.c @@ -432,6 +432,34 @@ qpt_thread_create(void* (*start)(void*), void* arg, qpt_thread_attr_t* attr) return thread_id ; } ; +/* Join given thread -- do nothing if !qpthreads_enabled + * + * Tolerates ESRCH (no thread known by given id). + * + * Returns whatever the thread returns, NULL otherwise. + * + * NB: all other errors are FATAL. + */ +extern void* +qpt_thread_join(qpt_thread_t thread_id) +{ + int err ; + void* ret ; + + if (!qpthreads_enabled) + return NULL ; + + err = pthread_join(thread_id, &ret) ; + + if (err == 0) + return ret ; + + if (err == ESRCH) + return NULL ; + + zabort_err("pthread_join failed", err) ; +} ; + /*============================================================================== * Mutex initialise and destroy. */ diff --git a/lib/qpthreads.h b/lib/qpthreads.h index 361271ff..2fbbea9a 100644 --- a/lib/qpthreads.h +++ b/lib/qpthreads.h @@ -123,6 +123,9 @@ qpt_thread_attr_init(qpt_thread_attr_t* attr, enum qpt_attr_options opts, extern qpt_thread_t /* FATAL error if !qpthreads_enabled */ qpt_thread_create(void* (*start)(void*), void* arg, qpt_thread_attr_t* attr) ; +extern void* /* do nothing if !qpthreads_enabled */ +qpt_thread_join(qpt_thread_t thread_id) ; + /*============================================================================== * qpthreads_enabled support -- NOT FOR PUBLIC CONSUMPTION ! */ |