mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2024-12-25 18:38:30 +01:00
potential fix for Windows 7 freeze on exit
This commit is contained in:
parent
7079ddb74e
commit
b7a0f849cf
@ -47,15 +47,14 @@ void ConfigManager::save(bool lock) {
|
||||
}
|
||||
|
||||
void ConfigManager::enableAutoSave() {
|
||||
if (!autoSaveEnabled) {
|
||||
if (autoSaveEnabled) { return; }
|
||||
autoSaveEnabled = true;
|
||||
termFlag = false;
|
||||
autoSaveThread = std::thread(autoSaveWorker, this);
|
||||
}
|
||||
autoSaveThread = std::thread(&ConfigManager::autoSaveWorker, this);
|
||||
}
|
||||
|
||||
void ConfigManager::disableAutoSave() {
|
||||
if (autoSaveEnabled) {
|
||||
if (!autoSaveEnabled) { return; }
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(termMtx);
|
||||
autoSaveEnabled = false;
|
||||
@ -63,35 +62,34 @@ void ConfigManager::disableAutoSave() {
|
||||
}
|
||||
termCond.notify_one();
|
||||
if (autoSaveThread.joinable()) { autoSaveThread.join(); }
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigManager::acquire() {
|
||||
mtx.lock();
|
||||
}
|
||||
|
||||
void ConfigManager::release(bool changed) {
|
||||
this->changed |= changed;
|
||||
void ConfigManager::release(bool modified) {
|
||||
changed |= modified;
|
||||
mtx.unlock();
|
||||
}
|
||||
|
||||
void ConfigManager::autoSaveWorker(ConfigManager* _this) {
|
||||
while (_this->autoSaveEnabled) {
|
||||
if (!_this->mtx.try_lock()) {
|
||||
void ConfigManager::autoSaveWorker() {
|
||||
while (autoSaveEnabled) {
|
||||
if (!mtx.try_lock()) {
|
||||
spdlog::warn("ConfigManager locked, waiting...");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
continue;
|
||||
}
|
||||
if (_this->changed) {
|
||||
_this->changed = false;
|
||||
_this->save(false);
|
||||
if (changed) {
|
||||
changed = false;
|
||||
save(false);
|
||||
}
|
||||
_this->mtx.unlock();
|
||||
mtx.unlock();
|
||||
|
||||
// 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; } );
|
||||
std::unique_lock<std::mutex> lock(termMtx);
|
||||
termCond.wait_for(lock, std::chrono::milliseconds(1000), [this]() { return termFlag; } );
|
||||
}
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <atomic>
|
||||
|
||||
using nlohmann::json;
|
||||
|
||||
@ -17,21 +18,21 @@ public:
|
||||
void enableAutoSave();
|
||||
void disableAutoSave();
|
||||
void acquire();
|
||||
void release(bool changed = false);
|
||||
void release(bool modified = false);
|
||||
|
||||
json conf;
|
||||
|
||||
private:
|
||||
static void autoSaveWorker(ConfigManager* _this);
|
||||
void autoSaveWorker();
|
||||
|
||||
std::string path = "";
|
||||
bool changed = false;
|
||||
bool autoSaveEnabled = false;
|
||||
volatile bool changed = false;
|
||||
volatile bool autoSaveEnabled = false;
|
||||
std::thread autoSaveThread;
|
||||
std::mutex mtx;
|
||||
|
||||
std::mutex termMtx;
|
||||
std::condition_variable termCond;
|
||||
bool termFlag = false;
|
||||
volatile bool termFlag = false;
|
||||
|
||||
};
|
@ -463,6 +463,11 @@ int sdrpp_main(int argc, char *argv[]) {
|
||||
glfwSwapBuffers(core::window);
|
||||
}
|
||||
|
||||
// Shut down all modules
|
||||
for (auto& [name, mod] : core::moduleManager.modules) {
|
||||
mod.end();
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
@ -473,5 +478,8 @@ int sdrpp_main(int argc, char *argv[]) {
|
||||
|
||||
sigpath::signalPath.stop();
|
||||
|
||||
core::configManager.disableAutoSave();
|
||||
core::configManager.save();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -866,5 +866,6 @@ MOD_EXPORT void _DELETE_INSTANCE_(void* instance) {
|
||||
}
|
||||
|
||||
MOD_EXPORT void _END_() {
|
||||
// Nothing here
|
||||
config.disableAutoSave();
|
||||
config.save();
|
||||
}
|
Loading…
Reference in New Issue
Block a user