Skip to content

Commit

Permalink
thread_halt_and_destroy() now wakes threads via optional cond and mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
00pauln00 committed Jul 23, 2024
1 parent 4c66e53 commit 17ec4e3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/include/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions src/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 17ec4e3

Please sign in to comment.