summaryrefslogtreecommitdiffhomepage
path: root/options/scoped.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'options/scoped.cpp')
-rw-r--r--options/scoped.cpp29
1 files changed, 23 insertions, 6 deletions
diff --git a/options/scoped.cpp b/options/scoped.cpp
index ef2b1b02..2974dfdb 100644
--- a/options/scoped.cpp
+++ b/options/scoped.cpp
@@ -9,9 +9,13 @@
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);
+static void set_teardown_flag(bool value);
+static void ensure_thread();
+static bool is_tracker_teardown();
-void opts::set_teardown_flag(bool value)
+static void 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.
@@ -19,10 +23,13 @@ void opts::set_teardown_flag(bool value)
teardown_flag = value;
}
-void opts::ensure_thread()
+static void ensure_thread()
{
// only as a bug check
+ if (qApp == nullptr)
+ abort();
+
const QThread* ui_thread = qApp->thread();
const QThread* curthread = QThread::currentThread();
@@ -33,6 +40,11 @@ void opts::ensure_thread()
abort();
}
+static bool is_tracker_teardown()
+{
+ return teardown_flag;
+}
+
opts::~opts()
{
if (!is_tracker_teardown())
@@ -43,13 +55,18 @@ opts::~opts()
#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(teardown_flag)
+{
+ set_teardown_flag(true);
+}
+
+with_tracker_teardown::~with_tracker_teardown()
{
+ set_teardown_flag(old_value);
}
} // ns options