Add a cleanup handler for the notify main thread

Make sure we do not leave behind unusable mutexes when calling
pthread_cancel().

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2014-07-16 23:19:10 +02:00
parent e6b0282a18
commit e93030befb

View File

@ -321,6 +321,15 @@ void notify_update_bar(void)
pthread_mutex_unlock(&notify.mutex); pthread_mutex_unlock(&notify.mutex);
} }
static void
notify_main_thread_cleanup(void *arg)
{
pthread_mutex_trylock(&notify.mutex);
pthread_mutex_unlock(&notify.mutex);
pthread_mutex_trylock(&nbar.mutex);
pthread_mutex_unlock(&nbar.mutex);
}
/* Update the notication bar content */ /* Update the notication bar content */
/* ARGSUSED0 */ /* ARGSUSED0 */
static void *notify_main_thread(void *arg) static void *notify_main_thread(void *arg)
@ -334,6 +343,8 @@ static void *notify_main_thread(void *arg)
elapse = 0; elapse = 0;
pthread_cleanup_push(notify_main_thread_cleanup, NULL);
for (;;) { for (;;) {
ntimer = time(NULL); ntimer = time(NULL);
localtime_r(&ntimer, &ntime); localtime_r(&ntimer, &ntime);
@ -357,6 +368,8 @@ static void *notify_main_thread(void *arg)
notify_check_next_app(0); notify_check_next_app(0);
} }
} }
pthread_cleanup_pop(0);
pthread_exit(NULL); pthread_exit(NULL);
} }