From 17ec4e398faaab341f495881bb3ae5e402eac1a6 Mon Sep 17 00:00:00 2001 From: Paul Nowoczynski Date: Tue, 23 Jul 2024 13:36:51 -0400 Subject: [PATCH] thread_halt_and_destroy() now wakes threads via optional cond and mutex --- src/include/thread.h | 13 +++++++++++++ src/thread.c | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/src/include/thread.h b/src/include/thread.h index b562f204f..4579455c4 100644 --- a/src/include/thread.h +++ b/src/include/thread.h @@ -47,6 +47,8 @@ struct thread_ctl void *tc_arg; size_t tc_sig_cnt; struct watchdog_handle tc_watchdog_handle; + pthread_mutex_t *tc_waiting_mutex; + pthread_cond_t *tc_waiting_cond; }; static inline enum tc_flags @@ -159,6 +161,17 @@ thread_ctl_thread_is_watched(const struct thread_ctl *tc) return (tc && thread_ctl_has_flag(tc, TC_FLAG_WATCHDOG)) ? true : false; } +static inline void +thread_ctl_apply_cond_and_mutex(struct thread_ctl *tc, pthread_cond_t *cond, + pthread_mutex_t *mutex) +{ + if (tc && cond && mutex) + { + tc->tc_waiting_cond = cond; + tc->tc_waiting_mutex = mutex; + } +} + thread_id_t thread_id_get(void); diff --git a/src/thread.c b/src/thread.c index d77b6fbf2..27f0e1bde 100644 --- a/src/thread.c +++ b/src/thread.c @@ -299,6 +299,12 @@ thread_halt_and_destroy(struct thread_ctl *tc) thread_ctl_remove_from_watchdog(tc); + if (tc->tc_waiting_cond && tc->tc_waiting_mutex) + { + NIOVA_SET_COND_AND_WAKE(broadcast, {}, tc->tc_waiting_mutex, + tc->tc_waiting_cond); + } + void *retval; int my_errno = 0;