1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-18 02:55:12 +00:00

It feels much better to let the thread exit voluntarily instead of violently killing it

This commit is contained in:
Pavel Labath 2009-09-20 14:38:57 +02:00
parent d45aa362b0
commit 596449c902

View File

@ -387,11 +387,12 @@ static struct update_cb {
void (*func)(void); void (*func)(void);
pthread_t thread; pthread_t thread;
sem_t start_wait, end_wait; sem_t start_wait, end_wait;
volatile char cancel;
} update_cb_head = { } update_cb_head = {
.next = NULL, .next = NULL,
}; };
static void *run_update_callback(void *) __attribute__((noreturn)); static void *run_update_callback(void *);
/* Register an update callback. Don't allow duplicates, to minimise side /* Register an update callback. Don't allow duplicates, to minimise side
* effects and overhead. */ * effects and overhead. */
@ -426,7 +427,7 @@ static void __free_update_callbacks(struct update_cb *uc)
__free_update_callbacks(uc->next); __free_update_callbacks(uc->next);
/* send cancellation request, then trigger and join the thread */ /* send cancellation request, then trigger and join the thread */
pthread_cancel(uc->thread); uc->cancel = 1;
sem_post(&uc->start_wait); sem_post(&uc->start_wait);
pthread_join(uc->thread, NULL); pthread_join(uc->thread, NULL);
@ -451,6 +452,8 @@ static void *run_update_callback(void *data)
while (1) { while (1) {
sem_wait(&ucb->start_wait); sem_wait(&ucb->start_wait);
if(ucb->cancel)
return NULL;
(*ucb->func)(); (*ucb->func)();
sem_post(&ucb->end_wait); sem_post(&ucb->end_wait);
} }