From 38c9e2c894b97b1455da18444de673ac959f3a33 Mon Sep 17 00:00:00 2001 From: Ryzerth Date: Wed, 21 Apr 2021 18:36:45 +0200 Subject: [PATCH 1/4] Fixed delay before exiting --- core/src/config.cpp | 11 ++++++++++- core/src/config.h | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/core/src/config.cpp b/core/src/config.cpp index 6a5fc31..cb57cf5 100644 --- a/core/src/config.cpp +++ b/core/src/config.cpp @@ -48,13 +48,17 @@ void ConfigManager::save(bool lock) { void ConfigManager::enableAutoSave() { if (!autoSaveEnabled) { autoSaveEnabled = true; + termFlag = false; autoSaveThread = std::thread(autoSaveWorker, this); } } void ConfigManager::disableAutoSave() { if (autoSaveEnabled) { + std::unique_lock lock(termMtx); autoSaveEnabled = false; + termFlag = true; + termCond.notify_one(); autoSaveThread.join(); } } @@ -80,6 +84,11 @@ void ConfigManager::autoSaveWorker(ConfigManager* _this) { _this->save(false); } _this->mtx.unlock(); - std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + + // Sleep but listen for wakeup call + { + std::unique_lock lock(_this->termMtx); + _this->termCond.wait_for(lock, std::chrono::milliseconds(1000), [_this]() { return _this->termFlag; } ); + } } } \ No newline at end of file diff --git a/core/src/config.h b/core/src/config.h index 277d7a4..697e460 100644 --- a/core/src/config.h +++ b/core/src/config.h @@ -29,4 +29,8 @@ private: std::thread autoSaveThread; std::mutex mtx; + std::mutex termMtx; + std::condition_variable termCond; + bool termFlag = false; + }; \ No newline at end of file From e236c420682d96beb1f83a510aa5878a3eb12be0 Mon Sep 17 00:00:00 2001 From: Ryzerth Date: Wed, 21 Apr 2021 18:39:47 +0200 Subject: [PATCH 2/4] Fixed missing include --- core/src/config.h | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/config.h b/core/src/config.h index 697e460..7fbbbe9 100644 --- a/core/src/config.h +++ b/core/src/config.h @@ -3,6 +3,7 @@ #include #include #include +#include using nlohmann::json; From 77dada07da16ecd56efaff4084ac62990e5feabf Mon Sep 17 00:00:00 2001 From: Ryzerth Date: Wed, 21 Apr 2021 19:24:58 +0200 Subject: [PATCH 3/4] Fixed sdrpp not exiting --- core/src/config.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/src/config.cpp b/core/src/config.cpp index cb57cf5..911376c 100644 --- a/core/src/config.cpp +++ b/core/src/config.cpp @@ -55,10 +55,12 @@ void ConfigManager::enableAutoSave() { void ConfigManager::disableAutoSave() { if (autoSaveEnabled) { - std::unique_lock lock(termMtx); - autoSaveEnabled = false; - termFlag = true; - termCond.notify_one(); + { + std::unique_lock lock(termMtx); + autoSaveEnabled = false; + termFlag = true; + termCond.notify_one(); + } autoSaveThread.join(); } } From eb8cd09e65de7b0a459fbcf3ce602f8e92129114 Mon Sep 17 00:00:00 2001 From: Ryzerth Date: Wed, 21 Apr 2021 20:06:30 +0200 Subject: [PATCH 4/4] Another fix for the weird no exit thing --- core/src/config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/config.cpp b/core/src/config.cpp index 911376c..b934b05 100644 --- a/core/src/config.cpp +++ b/core/src/config.cpp @@ -56,7 +56,7 @@ void ConfigManager::enableAutoSave() { void ConfigManager::disableAutoSave() { if (autoSaveEnabled) { { - std::unique_lock lock(termMtx); + std::lock_guard lock(termMtx); autoSaveEnabled = false; termFlag = true; termCond.notify_one();