aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@calcurse.org>2018-06-03 10:26:24 +0200
committerLukas Fleischer <lfleischer@calcurse.org>2018-06-03 10:28:28 +0200
commit30f411257ad3bc233184c08b846a2980a9c5d1f0 (patch)
tree03e05c13d8c44033eecfbb0a9b2a5b3db867a7de
parente55aead1267fedfca3485699716cd4031a508df3 (diff)
downloadcalcurse-30f411257ad3bc233184c08b846a2980a9c5d1f0.tar.gz
calcurse-30f411257ad3bc233184c08b846a2980a9c5d1f0.zip
Do not stop already cancelled notification thread
Add a static state variable to indicate whether the notification thread is already running or not. Only start the thread if the notification thread is paused. Only stop the thread if the notification thread is actually running. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
-rw-r--r--src/notify.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/notify.c b/src/notify.c
index 886a7e6..7475611 100644
--- a/src/notify.c
+++ b/src/notify.c
@@ -55,6 +55,7 @@ static struct notify_vars notify;
static struct notify_app notify_app;
static pthread_attr_t detached_thread_attr;
static pthread_t notify_t_main;
+static int notify_t_main_running;
/*
* Return the number of seconds before next appointment
@@ -193,10 +194,12 @@ void notify_free_app(void)
/* Stop the notify-bar main thread. */
void notify_stop_main_thread(void)
{
- if (notify_t_main) {
- pthread_cancel(notify_t_main);
- pthread_join(notify_t_main, NULL);
- }
+ if (!notify_t_main_running)
+ return;
+
+ pthread_cancel(notify_t_main);
+ pthread_join(notify_t_main, NULL);
+ notify_t_main_running = 0;
}
/*
@@ -552,10 +555,12 @@ int notify_same_recur_item(struct recur_apoint *i)
/* Launch the notify-bar main thread. */
void notify_start_main_thread(void)
{
- /* Avoid starting the notification bar thread twice. */
- notify_stop_main_thread();
+ if (notify_t_main_running)
+ return;
pthread_create(&notify_t_main, NULL, notify_main_thread, NULL);
+ notify_t_main_running = 1;
+
notify_check_next_app(0);
}