aboutsummaryrefslogtreecommitdiffstats
path: root/src/io.c
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2014-07-16 23:36:02 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2014-07-16 23:39:07 +0200
commitb37ed2fcc8a4c64419cf066d3c940fc29b7a2d73 (patch)
tree553886da83ecfb6f726dde332ceac085913d287e /src/io.c
parent5aec5408950ed41fad203e749bda225bd3f86a8b (diff)
downloadcalcurse-b37ed2fcc8a4c64419cf066d3c940fc29b7a2d73.tar.gz
calcurse-b37ed2fcc8a4c64419cf066d3c940fc29b7a2d73.zip
Avoid cancelling the save thread during saving
Ensure that we never cancel the periodic save thread when it currently saves the configuration and data files. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Diffstat (limited to 'src/io.c')
-rw-r--r--src/io.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/io.c b/src/io.c
index f24b0f7..95a42d3 100644
--- a/src/io.c
+++ b/src/io.c
@@ -1214,10 +1214,14 @@ void io_start_psave_thread(void)
/* Stop periodic data saves. */
void io_stop_psave_thread(void)
{
- if (io_t_psave) {
- pthread_cancel(io_t_psave);
- pthread_join(io_t_psave, NULL);
- }
+ if (!io_t_psave)
+ return;
+
+ /* Lock the mutex to avoid cancelling the thread during saving. */
+ io_save_mutex_lock();
+ pthread_cancel(io_t_psave);
+ pthread_join(io_t_psave, NULL);
+ io_save_mutex_unlock();
}
/*