summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gui/main-window.cpp4
-rw-r--r--logic/runtime-libraries.cpp6
-rw-r--r--options/scoped.cpp29
-rw-r--r--options/scoped.hpp16
4 files changed, 35 insertions, 20 deletions
diff --git a/gui/main-window.cpp b/gui/main-window.cpp
index d049facc..d03dbb82 100644
--- a/gui/main-window.cpp
+++ b/gui/main-window.cpp
@@ -490,7 +490,7 @@ void MainWindow::stop_tracker_()
if (!work)
return;
- opts::set_teardown_flag(true); // XXX hack -sh 20160926
+ with_tracker_teardown sentinel;
pose_update_timer.stop();
ui.pose_display->rotate_sync(0,0,0, 0,0,0);
@@ -511,8 +511,6 @@ void MainWindow::stop_tracker_()
display_pose(p, p);
}
- opts::set_teardown_flag(false); // XXX hack -sh 20160926
-
update_button_state(false, false);
set_title();
ui.btnStartTracker->setFocus();
diff --git a/logic/runtime-libraries.cpp b/logic/runtime-libraries.cpp
index eb5f02cc..a04da6a2 100644
--- a/logic/runtime-libraries.cpp
+++ b/logic/runtime-libraries.cpp
@@ -10,9 +10,7 @@ runtime_libraries::runtime_libraries(QFrame* frame, dylibptr t, dylibptr p, dyli
{
using namespace options;
- const bool prev_teardown_flag = opts::is_tracker_teardown();
-
- opts::set_teardown_flag(true);
+ with_tracker_teardown sentinel;
pProtocol = make_dylib_instance<IProtocol>(p);
@@ -42,6 +40,6 @@ runtime_libraries::runtime_libraries(QFrame* frame, dylibptr t, dylibptr p, dyli
correct = true;
end:
- opts::set_teardown_flag(prev_teardown_flag);
+ (void)0;
}
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();
};
}