Periodic save mutex
To protect the periodic save from being cancelled during a save operation. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
parent
657f007cd2
commit
837f629341
8
src/io.c
8
src/io.c
@ -210,6 +210,7 @@ void io_extract_data(char *dst_data, const char *org, int len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static pthread_mutex_t io_mutex = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t io_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
static pthread_mutex_t io_periodic_save_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
static void io_mutex_lock(void)
|
static void io_mutex_lock(void)
|
||||||
{
|
{
|
||||||
@ -1424,9 +1425,12 @@ static void *io_psave_thread(void *arg)
|
|||||||
int delay = conf.periodic_save;
|
int delay = conf.periodic_save;
|
||||||
EXIT_IF(delay < 0, _("Invalid delay"));
|
EXIT_IF(delay < 0, _("Invalid delay"));
|
||||||
|
|
||||||
|
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
sleep(delay * MININSEC);
|
sleep(delay * MININSEC);
|
||||||
|
pthread_mutex_lock(&io_periodic_save_mutex);
|
||||||
io_save_cal(periodic);
|
io_save_cal(periodic);
|
||||||
|
pthread_mutex_unlock(&io_periodic_save_mutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1444,10 +1448,10 @@ void io_stop_psave_thread(void)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
/* Lock the mutex to avoid cancelling the thread during saving. */
|
/* Lock the mutex to avoid cancelling the thread during saving. */
|
||||||
io_mutex_lock();
|
pthread_mutex_lock(&io_periodic_save_mutex);
|
||||||
pthread_cancel(io_t_psave);
|
pthread_cancel(io_t_psave);
|
||||||
pthread_join(io_t_psave, NULL);
|
pthread_join(io_t_psave, NULL);
|
||||||
io_mutex_unlock();
|
pthread_mutex_unlock(&io_periodic_save_mutex);
|
||||||
io_t_psave = pthread_self();
|
io_t_psave = pthread_self();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user