diff --git a/daemon/helpers.c b/daemon/helpers.c index 4fbc5d70b..bd4bffca7 100644 --- a/daemon/helpers.c +++ b/daemon/helpers.c @@ -134,9 +134,7 @@ void threads_join_all(bool cancel) { mutex_lock(&thread_wakers_lock); for (l = thread_wakers; l; l = l->next) { struct thread_waker *wk = l->data; - mutex_lock(wk->lock); - cond_broadcast(wk->cond); - mutex_unlock(wk->lock); + wk->func(wk); } mutex_unlock(&thread_wakers_lock); @@ -172,7 +170,16 @@ void threads_join_all(bool cancel) { } } +static void thread_waker_wake_cond(struct thread_waker *wk) { + mutex_lock(wk->lock); + cond_broadcast(wk->cond); + mutex_unlock(wk->lock); +} void thread_waker_add(struct thread_waker *wk) { + wk->func = thread_waker_wake_cond; + thread_waker_add_generic(wk); +} +void thread_waker_add_generic(struct thread_waker *wk) { mutex_lock(&thread_wakers_lock); thread_wakers = g_list_prepend(thread_wakers, wk); mutex_unlock(&thread_wakers_lock); diff --git a/include/helpers.h b/include/helpers.h index 99d76b4c9..601647f28 100644 --- a/include/helpers.h +++ b/include/helpers.h @@ -212,8 +212,10 @@ INLINE void swap_ptrs(void *a, void *b) { /*** THREAD HELPERS ***/ struct thread_waker { + void (*func)(struct thread_waker *); mutex_t *lock; cond_t *cond; + void *arg; }; enum thread_looper_action { TLA_CONTINUE, @@ -221,6 +223,7 @@ enum thread_looper_action { }; void thread_waker_add(struct thread_waker *); +void thread_waker_add_generic(struct thread_waker *); void thread_waker_del(struct thread_waker *); void threads_join_all(bool cancel); void thread_create_detach_prio(void (*)(void *), void *, const char *, int, const char *);