blob: b0677ad904878be5d1dedcd5b2693f280bda947f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#include "scoped.hpp"
#include <QApplication>
#include <QThread>
// for std::abort()
#include <cstdlib>
#include <QDebug>
namespace options {
std::atomic_bool opts::teardown_flag(false);
void opts::set_teardown_flag(bool value)
{
ensure_thread();
// we don't use exceptions in the whole project so no need for unwind protection
// also the calls aren't nested so no need for CAS either
teardown_flag = value;
}
void opts::ensure_thread()
{
// only as a bug check
const QThread* ui_thread = qApp->thread();
const QThread* curthread = QThread::currentThread();
if (ui_thread == nullptr)
abort();
if (ui_thread != curthread)
abort();
}
opts::~opts()
{
if (!is_tracker_teardown())
b->reload();
#if 0
else
qDebug() << "in teardown, not reloading" << b->name();
#endif
}
bool opts::is_tracker_teardown()
{
return teardown_flag;
}
opts::opts(const QString &name) : b(make_bundle(name))
{
}
}
|