From: Pavel Labath Date: Sun, 20 Sep 2009 12:38:57 +0000 (+0200) Subject: It feels much better to let the thread exit voluntarily instead of violently killing it X-Git-Url: http://git.maemo.org/git/?a=commitdiff_plain;h=596449c9025c78d370beadadd62a52e28c20800f;p=monky It feels much better to let the thread exit voluntarily instead of violently killing it --- diff --git a/src/common.c b/src/common.c index 4d9450b..50488d1 100644 --- a/src/common.c +++ b/src/common.c @@ -387,11 +387,12 @@ static struct update_cb { void (*func)(void); pthread_t thread; sem_t start_wait, end_wait; + volatile char cancel; } update_cb_head = { .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 * effects and overhead. */ @@ -426,7 +427,7 @@ static void __free_update_callbacks(struct update_cb *uc) __free_update_callbacks(uc->next); /* send cancellation request, then trigger and join the thread */ - pthread_cancel(uc->thread); + uc->cancel = 1; sem_post(&uc->start_wait); pthread_join(uc->thread, NULL); @@ -451,6 +452,8 @@ static void *run_update_callback(void *data) while (1) { sem_wait(&ucb->start_wait); + if(ucb->cancel) + return NULL; (*ucb->func)(); sem_post(&ucb->end_wait); }