mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2024-12-24 18:08:27 +01:00
Fixed delay before exiting
This commit is contained in:
parent
4849d9cf09
commit
38c9e2c894
@ -48,13 +48,17 @@ 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) {
|
||||||
|
std::unique_lock<std::mutex> lock(termMtx);
|
||||||
autoSaveEnabled = false;
|
autoSaveEnabled = false;
|
||||||
|
termFlag = true;
|
||||||
|
termCond.notify_one();
|
||||||
autoSaveThread.join();
|
autoSaveThread.join();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,6 +84,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; } );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -29,4 +29,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…
Reference in New Issue
Block a user