summaryrefslogtreecommitdiffhomepage
path: root/options
diff options
context:
space:
mode:
Diffstat (limited to 'options')
-rw-r--r--options/scoped.cpp29
-rw-r--r--options/scoped.hpp16
2 files changed, 32 insertions, 13 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
diff --git a/options/scoped.hpp b/options/scoped.hpp
index f43e9712..117bbf56 100644
--- a/options/scoped.hpp
+++ b/options/scoped.hpp
@@ -9,6 +9,15 @@
namespace options {
+struct OTR_OPTIONS_EXPORT with_tracker_teardown final
+{
+ with_tracker_teardown();
+ ~with_tracker_teardown();
+
+private:
+ bool old_value;
+};
+
struct OTR_OPTIONS_EXPORT opts
{
bundle b;
@@ -16,13 +25,6 @@ struct OTR_OPTIONS_EXPORT opts
opts& operator=(const opts&) = delete;
opts(const opts&) = delete;
virtual ~opts();
-
- // XXX hack: the flag shouldn't be here as action at distance -sh 20160926
- static void set_teardown_flag(bool value);
- static bool is_tracker_teardown();
-private:
- static std::atomic_bool teardown_flag;
- static void ensure_thread();
};
}