summaryrefslogtreecommitdiffhomepage
path: root/options/scoped.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-10-20 18:06:24 +0200
committerStanislaw Halik <sthalik@misaki.pl>2017-10-20 18:06:33 +0200
commitb947e4a4ae0e06633b114dd59d447973fc5aaa56 (patch)
tree7933c169ed263f30ef0389f2059da14e3c5ad933 /options/scoped.cpp
parent39e209983bd1f04fb0beefef754d7430c8b7fb9f (diff)
options/scoped: use raii
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