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>
This commit is contained in:
parent
e55aead126
commit
30f411257a
17
src/notify.c
17
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(¬ify_t_main, NULL, notify_main_thread, NULL);
|
||||
notify_t_main_running = 1;
|
||||
|
||||
notify_check_next_app(0);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user