From 837f6293415e72603832a5864e449ee2bad70a2f Mon Sep 17 00:00:00 2001 From: Lars Henriksen Date: Fri, 31 Aug 2018 21:36:04 +0200 Subject: Periodic save mutex To protect the periodic save from being cancelled during a save operation. Signed-off-by: Lars Henriksen Signed-off-by: Lukas Fleischer --- src/io.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/io.c') diff --git a/src/io.c b/src/io.c index 16fddc3..9cfae0f 100644 --- a/src/io.c +++ b/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_periodic_save_mutex = PTHREAD_MUTEX_INITIALIZER; static void io_mutex_lock(void) { @@ -1424,9 +1425,12 @@ static void *io_psave_thread(void *arg) int delay = conf.periodic_save; EXIT_IF(delay < 0, _("Invalid delay")); + pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); for (;;) { sleep(delay * MININSEC); + pthread_mutex_lock(&io_periodic_save_mutex); io_save_cal(periodic); + pthread_mutex_unlock(&io_periodic_save_mutex); } } @@ -1444,10 +1448,10 @@ void io_stop_psave_thread(void) return; /* 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_join(io_t_psave, NULL); - io_mutex_unlock(); + pthread_mutex_unlock(&io_periodic_save_mutex); io_t_psave = pthread_self(); } -- cgit v1.2.3-54-g00ecf