summaryrefslogtreecommitdiffhomepage
path: root/options/scoped.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'options/scoped.cpp')
-rw-r--r--options/scoped.cpp43
1 files changed, 33 insertions, 10 deletions
diff --git a/options/scoped.cpp b/options/scoped.cpp
index 96f4a261..33db7907 100644
--- a/options/scoped.cpp
+++ b/options/scoped.cpp
@@ -1,29 +1,37 @@
#include "scoped.hpp"
+#include "compat/run-in-thread.hpp"
#include <QApplication>
#include <QThread>
-// for std::abort()
#include <cstdlib>
+#include <atomic>
#include <QDebug>
namespace options {
-std::atomic_bool opts::teardown_flag(false);
+// XXX hack: the flag shouldn't be here as action at distance -sh 20160926
+static std::atomic<bool> teardown_flag = false;
+[[nodiscard]] static bool set_teardown_flag(bool value);
+static void ensure_thread();
+static bool is_tracker_teardown();
-void opts::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);
}
-void opts::ensure_thread()
+static void ensure_thread()
{
// only as a bug check
- const QThread* ui_thread = qApp->thread();
+ if (qApp == nullptr) // NOLINT
+ abort();
+
+ const QThread* ui_thread = qApp->thread(); // NOLINT
const QThread* curthread = QThread::currentThread();
if (ui_thread == nullptr)
@@ -33,23 +41,38 @@ void opts::ensure_thread()
abort();
}
+static bool is_tracker_teardown()
+{
+ return teardown_flag;
+}
+
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();
#endif
}
-bool opts::is_tracker_teardown()
+opts::opts(const QString &name) : b(make_bundle(name))
{
- return teardown_flag;
}
-opts::opts(const QString &name) : b(make_bundle(name))
+with_tracker_teardown::with_tracker_teardown() : old_value{set_teardown_flag(true)}
{
}
+with_tracker_teardown::~with_tracker_teardown()
+{
+ (void)set_teardown_flag(old_value);
}
+
+} // ns options