summaryrefslogtreecommitdiffhomepage
path: root/options/scoped.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'options/scoped.cpp')
-rw-r--r--options/scoped.cpp26
1 files changed, 16 insertions, 10 deletions
diff --git a/options/scoped.cpp b/options/scoped.cpp
index 2974dfdb..33db7907 100644
--- a/options/scoped.cpp
+++ b/options/scoped.cpp
@@ -1,4 +1,5 @@
#include "scoped.hpp"
+#include "compat/run-in-thread.hpp"
#include <QApplication>
#include <QThread>
@@ -10,27 +11,27 @@
namespace options {
// XXX hack: the flag shouldn't be here as action at distance -sh 20160926
-static std::atomic_bool teardown_flag(false);
-static void set_teardown_flag(bool value);
+static std::atomic<bool> teardown_flag = false;
+[[nodiscard]] static bool set_teardown_flag(bool value);
static void ensure_thread();
static bool is_tracker_teardown();
-static void set_teardown_flag(bool value)
+static bool set_teardown_flag(bool value)
{
// flag being set means "opts" is about to go out of scope due to tracker stop
// in this case we don't reload options. we only want to reload when cancel is pressed.
ensure_thread();
- teardown_flag = value;
+ return teardown_flag.exchange(value);
}
static void ensure_thread()
{
// only as a bug check
- if (qApp == nullptr)
+ if (qApp == nullptr) // NOLINT
abort();
- const QThread* ui_thread = qApp->thread();
+ const QThread* ui_thread = qApp->thread(); // NOLINT
const QThread* curthread = QThread::currentThread();
if (ui_thread == nullptr)
@@ -47,8 +48,14 @@ static bool is_tracker_teardown()
opts::~opts()
{
- if (!is_tracker_teardown())
+ // XXX TODO debug crash with ps3eye dialog in pt tracker -sh 20211019
+ if (!is_tracker_teardown() && raii)
+#if 1
+ run_in_thread_sync(qApp->thread(), [this]{ b->reload(); });
+#else
+ assert(b);
b->reload();
+#endif
#if 0
else
qDebug() << "in teardown, not reloading" << b->name();
@@ -59,14 +66,13 @@ opts::opts(const QString &name) : b(make_bundle(name))
{
}
-with_tracker_teardown::with_tracker_teardown() : old_value(teardown_flag)
+with_tracker_teardown::with_tracker_teardown() : old_value{set_teardown_flag(true)}
{
- set_teardown_flag(true);
}
with_tracker_teardown::~with_tracker_teardown()
{
- set_teardown_flag(old_value);
+ (void)set_teardown_flag(old_value);
}
} // ns options