summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Henriksen <LarsHenriksen@get2net.dk>2018-08-31 21:36:04 +0200
committerLukas Fleischer <lfleischer@calcurse.org>2018-10-21 20:02:57 +0200
commit837f6293415e72603832a5864e449ee2bad70a2f (patch)
tree929fcbbb6ebb67965fd2c0ac7f28f0e81e6dd8cb /src
parent657f007cd294b9743d9a64e52c9ccdca8b3de3e1 (diff)
downloadcalcurse-837f6293415e72603832a5864e449ee2bad70a2f.tar.gz
calcurse-837f6293415e72603832a5864e449ee2bad70a2f.zip
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>
Diffstat (limited to 'src')
-rw-r--r--src/io.c8
1 files changed, 6 insertions, 2 deletions
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();
}