mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-03-26 17:45:28 +01:00
Merge branch 'master' of https://github.com/Starman0620/SDRPlusPlus; branch 'master' of https://github.com/AlexandreRouma/SDRPlusPlus
This commit is contained in:
commit
7ee86a5d40
@ -48,13 +48,19 @@ void ConfigManager::save(bool lock) {
|
|||||||
void ConfigManager::enableAutoSave() {
|
void ConfigManager::enableAutoSave() {
|
||||||
if (!autoSaveEnabled) {
|
if (!autoSaveEnabled) {
|
||||||
autoSaveEnabled = true;
|
autoSaveEnabled = true;
|
||||||
|
termFlag = false;
|
||||||
autoSaveThread = std::thread(autoSaveWorker, this);
|
autoSaveThread = std::thread(autoSaveWorker, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigManager::disableAutoSave() {
|
void ConfigManager::disableAutoSave() {
|
||||||
if (autoSaveEnabled) {
|
if (autoSaveEnabled) {
|
||||||
autoSaveEnabled = false;
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(termMtx);
|
||||||
|
autoSaveEnabled = false;
|
||||||
|
termFlag = true;
|
||||||
|
termCond.notify_one();
|
||||||
|
}
|
||||||
autoSaveThread.join();
|
autoSaveThread.join();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,6 +86,11 @@ void ConfigManager::autoSaveWorker(ConfigManager* _this) {
|
|||||||
_this->save(false);
|
_this->save(false);
|
||||||
}
|
}
|
||||||
_this->mtx.unlock();
|
_this->mtx.unlock();
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
|
||||||
|
// Sleep but listen for wakeup call
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(_this->termMtx);
|
||||||
|
_this->termCond.wait_for(lock, std::chrono::milliseconds(1000), [_this]() { return _this->termFlag; } );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,6 +3,7 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <condition_variable>
|
||||||
|
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
@ -29,4 +30,8 @@ private:
|
|||||||
std::thread autoSaveThread;
|
std::thread autoSaveThread;
|
||||||
std::mutex mtx;
|
std::mutex mtx;
|
||||||
|
|
||||||
|
std::mutex termMtx;
|
||||||
|
std::condition_variable termCond;
|
||||||
|
bool termFlag = false;
|
||||||
|
|
||||||
};
|
};
|
Loading…
x
Reference in New Issue
Block a user