MT#55283 generalise thread_waker

Allow other mechanisms for waking up a thread.

Change-Id: I29c8bc90b1b494e9299432af48f36155d256c0aa
pull/1826/head
Richard Fuchs 1 year ago
parent a3f6a9228d
commit 6aca3e88ad

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

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

Loading…
Cancel
Save