summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2014-07-16 23:19:10 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2014-07-16 23:19:10 +0200
commite93030befb2aebe94faf5c5455313d312611d7b3 (patch)
treebe68d2dcc3251e8dada80746d8ceb3f811ebe7cd
parente6b0282a1871da86d7255a17ee5cca62827e3777 (diff)
downloadcalcurse-e93030befb2aebe94faf5c5455313d312611d7b3.zip
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>
-rw-r--r--src/notify.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/notify.c b/src/notify.c
index 532bd01..0b02ebd 100644
--- a/src/notify.c
+++ b/src/notify.c
@@ -321,6 +321,15 @@ void notify_update_bar(void)
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 */
/* ARGSUSED0 */
static void *notify_main_thread(void *arg)
@@ -334,6 +343,8 @@ static void *notify_main_thread(void *arg)
elapse = 0;
+ pthread_cleanup_push(notify_main_thread_cleanup, NULL);
+
for (;;) {
ntimer = time(NULL);
localtime_r(&ntimer, &ntime);
@@ -357,6 +368,8 @@ static void *notify_main_thread(void *arg)
notify_check_next_app(0);
}
}
+
+ pthread_cleanup_pop(0);
pthread_exit(NULL);
}