summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2019-01-16 05:58:48 +0100
committerStanislaw Halik <sthalik@misaki.pl>2019-01-16 07:49:13 +0100
commit03d28dde1635e36508cff1f9eabc265cdb5febb9 (patch)
treeee62d5851315c7b4c2c3c05f8a72e29a6dd4a1e8
parentf8faca0abecafd6e65d07bd0fdd618070114cdfa (diff)
compat/mutex: remove
Always use the adaptive QMutex.
-rw-r--r--compat/check-visible.cpp11
-rw-r--r--compat/spinlock.hpp31
-rw-r--r--dinput/dinput.cpp7
-rw-r--r--dinput/dinput.hpp6
-rw-r--r--gui/init.cpp6
-rw-r--r--logic/pipeline.cpp6
-rw-r--r--logic/pipeline.hpp3
-rw-r--r--proto-udp/ftnoir_protocol_ftn.cpp7
-rw-r--r--proto-udp/ftnoir_protocol_ftn.h3
-rw-r--r--tracker-pt/ftnoir_tracker_pt.cpp13
-rw-r--r--tracker-pt/ftnoir_tracker_pt.h3
11 files changed, 29 insertions, 67 deletions
diff --git a/compat/check-visible.cpp b/compat/check-visible.cpp
index 2772c9ae..1212ab90 100644
--- a/compat/check-visible.cpp
+++ b/compat/check-visible.cpp
@@ -1,11 +1,10 @@
#include "check-visible.hpp"
+#include <QMutex>
#include <QWidget>
#include <QDebug>
-#include "spinlock.hpp"
-
-static std::atomic_flag lock = ATOMIC_FLAG_INIT;
+static QMutex lock;
static bool visible = true;
#if defined _WIN32
@@ -22,7 +21,7 @@ constexpr int invisible_timeout = 250;
void set_is_visible(const QWidget& w, bool force)
{
- spinlock_guard l(lock);
+ QMutexLocker l(&lock);
if (w.isHidden() || w.windowState() & Qt::WindowMinimized)
{
@@ -78,12 +77,12 @@ void set_is_visible(const QWidget& w, bool)
bool check_is_visible()
{
- spinlock_guard l(lock);
+ QMutexLocker l(&lock);
return visible;
}
void force_is_visible(bool value)
{
- spinlock_guard l(lock);
+ QMutexLocker l(&lock);
visible = value;
}
diff --git a/compat/spinlock.hpp b/compat/spinlock.hpp
deleted file mode 100644
index b94df7c8..00000000
--- a/compat/spinlock.hpp
+++ /dev/null
@@ -1,31 +0,0 @@
-#pragma once
-
-#include "export.hpp"
-#include "macros1.h"
-#include <atomic>
-
-struct OTR_COMPAT_EXPORT spinlock_guard final
-{
- spinlock_guard(const spinlock_guard&) = delete;
- spinlock_guard& operator=(const spinlock_guard&) = delete;
- constexpr spinlock_guard(spinlock_guard&&) noexcept = default;
-
- cc_forceinline
- spinlock_guard(std::atomic_flag* lock) noexcept : spinlock_guard(*lock) {}
-
- cc_forceinline
- spinlock_guard(std::atomic_flag& lock) noexcept : lock(lock)
- {
- while (lock.test_and_set(std::memory_order_acquire))
- (void)0;
- }
-
- cc_forceinline
- ~spinlock_guard() noexcept
- {
- lock.clear(std::memory_order_release);
- }
-
-private:
- std::atomic_flag& lock;
-};
diff --git a/dinput/dinput.cpp b/dinput/dinput.cpp
index 75f398ad..e896f5f1 100644
--- a/dinput/dinput.cpp
+++ b/dinput/dinput.cpp
@@ -1,10 +1,9 @@
#include "dinput.hpp"
-#include "compat/spinlock.hpp"
#include <QDebug>
int di_t::refcnt{0};
-std::atomic_flag di_t::lock = ATOMIC_FLAG_INIT;
diptr di_t::handle;
+QMutex di_t::lock;
diptr di_t::init_di_()
{
@@ -33,7 +32,7 @@ di_t::di_t()
void di_t::ref_di()
{
- spinlock_guard l(lock);
+ QMutexLocker l(&lock);
if (!handle)
handle = init_di_();
@@ -43,7 +42,7 @@ void di_t::ref_di()
void di_t::unref_di()
{
- spinlock_guard l(lock);
+ QMutexLocker l(&lock);
const int refcnt_ = --refcnt;
diff --git a/dinput/dinput.hpp b/dinput/dinput.hpp
index 7128229b..4bb3b458 100644
--- a/dinput/dinput.hpp
+++ b/dinput/dinput.hpp
@@ -8,9 +8,9 @@
#pragma once
-#include "export.hpp"
+#include <QMutex>
-#include <atomic>
+#include "export.hpp"
#undef DIRECTINPUT_VERSION
#define DIRECTINPUT_VERSION 0x800
@@ -26,7 +26,7 @@ class OTR_DINPUT_EXPORT di_t final
static diptr handle;
static int refcnt;
- static std::atomic_flag lock;
+ static QMutex lock;
static diptr init_di_();
public:
diff --git a/gui/init.cpp b/gui/init.cpp
index 5ed4ca00..07f6c6b1 100644
--- a/gui/init.cpp
+++ b/gui/init.cpp
@@ -27,6 +27,7 @@ using namespace options;
#include <QFileDialog>
#include <QString>
#include <QOperatingSystemVersion>
+#include <QMutex>
#include <QDebug>
@@ -101,7 +102,6 @@ static void set_qt_style()
#endif
}
-#include "compat/spinlock.hpp"
#include <string>
#ifdef _WIN32
@@ -118,8 +118,8 @@ static void qdebug_to_console(QtMsgType, const QMessageLogContext& ctx, const QS
if (IsDebuggerPresent())
{
- static std::atomic_flag lock = ATOMIC_FLAG_INIT;
- spinlock_guard l(lock);
+ static QMutex lock;
+ QMutexLocker l(&lock);
const wchar_t* const bytes = (const wchar_t*)msg.utf16();
diff --git a/logic/pipeline.cpp b/logic/pipeline.cpp
index 67669732..c355bf19 100644
--- a/logic/pipeline.cpp
+++ b/logic/pipeline.cpp
@@ -601,7 +601,7 @@ void pipeline::toggle_enabled() { b.negate(f_enabled_p); }
void bits::set(bit_flags flag, bool val)
{
- spinlock_guard l(lock);
+ QMutexLocker l(&lock);
flags &= ~flag;
if (val)
@@ -610,14 +610,14 @@ void bits::set(bit_flags flag, bool val)
void bits::negate(bit_flags flag)
{
- spinlock_guard l(lock);
+ QMutexLocker l(&lock);
flags ^= flag;
}
bool bits::get(bit_flags flag)
{
- spinlock_guard l(lock);
+ QMutexLocker l(&lock);
return !!(flags & flag);
}
diff --git a/logic/pipeline.hpp b/logic/pipeline.hpp
index 40088a5d..545a7836 100644
--- a/logic/pipeline.hpp
+++ b/logic/pipeline.hpp
@@ -7,7 +7,6 @@
#include "mappings.hpp"
#include "compat/euler.hpp"
#include "compat/enum-operators.hpp"
-#include "compat/spinlock.hpp"
#include "runtime-libraries.hpp"
#include "extensions.hpp"
@@ -70,7 +69,7 @@ enum bit_flags : unsigned {
struct OTR_LOGIC_EXPORT bits
{
bit_flags flags{0};
- std::atomic_flag lock = ATOMIC_FLAG_INIT;
+ QMutex lock;
void set(bit_flags flag, bool val);
void negate(bit_flags flag);
diff --git a/proto-udp/ftnoir_protocol_ftn.cpp b/proto-udp/ftnoir_protocol_ftn.cpp
index def3ebb1..000a0a79 100644
--- a/proto-udp/ftnoir_protocol_ftn.cpp
+++ b/proto-udp/ftnoir_protocol_ftn.cpp
@@ -21,15 +21,16 @@ udp::udp()
Qt::DirectConnection);
}
-void udp::pose(const double *headpose) {
- spinlock_guard l(spl);
+void udp::pose(const double *headpose)
+{
+ QMutexLocker l(&lock);
outSocket.writeDatagram((const char *) headpose, sizeof(double[6]), dest_ip, dest_port);
}
void udp::set_dest_address()
{
- spinlock_guard l(spl);
+ QMutexLocker l(&lock);
dest_port = (unsigned short)s.port;
dest_ip = QHostAddress((s.ip1.to<unsigned>() & 0xff) << 24 |
diff --git a/proto-udp/ftnoir_protocol_ftn.h b/proto-udp/ftnoir_protocol_ftn.h
index a7c90f5b..53387a6c 100644
--- a/proto-udp/ftnoir_protocol_ftn.h
+++ b/proto-udp/ftnoir_protocol_ftn.h
@@ -12,7 +12,6 @@
#include "ui_ftnoir_ftncontrols.h"
#include "api/plugin-api.hpp"
-#include "compat/spinlock.hpp"
#include "options/options.hpp"
using namespace options;
#include <QUdpSocket>
@@ -42,7 +41,7 @@ private:
QUdpSocket outSocket;
settings s;
- mutable std::atomic_flag spl = ATOMIC_FLAG_INIT;
+ mutable QMutex lock;
QHostAddress dest_ip { 127u << 24 | 1u };
unsigned short dest_port = 65535;
diff --git a/tracker-pt/ftnoir_tracker_pt.cpp b/tracker-pt/ftnoir_tracker_pt.cpp
index da295e39..76d10d1d 100644
--- a/tracker-pt/ftnoir_tracker_pt.cpp
+++ b/tracker-pt/ftnoir_tracker_pt.cpp
@@ -10,12 +10,9 @@
#include "cv/video-widget.hpp"
#include "compat/camera-names.hpp"
#include "compat/math-imports.hpp"
-#include "compat/spinlock.hpp"
#include "pt-api.hpp"
-#include <cmath>
-
#include <QHBoxLayout>
#include <QDebug>
#include <QFile>
@@ -77,7 +74,7 @@ void Tracker_PT::run()
Affine X_CM;
{
- spinlock_guard l(center_flag);
+ QMutexLocker l(&center_lock);
if (success)
{
@@ -88,7 +85,7 @@ void Tracker_PT::run()
ever_success = true;
}
- spinlock_guard l2(data_lock);
+ QMutexLocker l2(&data_lock);
X_CM = point_tracker.pose();
}
@@ -151,7 +148,7 @@ void Tracker_PT::data(double *data)
{
Affine X_CM;
{
- spinlock_guard l(&data_lock);
+ QMutexLocker l(&data_lock);
X_CM = point_tracker.pose();
}
@@ -189,7 +186,7 @@ void Tracker_PT::data(double *data)
bool Tracker_PT::center()
{
- spinlock_guard l(center_flag);
+ QMutexLocker l(&center_lock);
point_tracker.reset_state();
return false;
@@ -211,7 +208,7 @@ bool Tracker_PT::get_cam_info(pt_camera_info& info)
Affine Tracker_PT::pose() const
{
- spinlock_guard l(data_lock);
+ QMutexLocker l(&data_lock);
return point_tracker.pose();
}
diff --git a/tracker-pt/ftnoir_tracker_pt.h b/tracker-pt/ftnoir_tracker_pt.h
index 5e9ad9b3..0226fd87 100644
--- a/tracker-pt/ftnoir_tracker_pt.h
+++ b/tracker-pt/ftnoir_tracker_pt.h
@@ -75,8 +75,7 @@ private:
std::atomic<unsigned> point_count { 0 };
std::atomic<bool> ever_success { false };
- mutable std::atomic_flag center_flag = ATOMIC_FLAG_INIT;
- mutable std::atomic_flag data_lock = ATOMIC_FLAG_INIT;
+ mutable QMutex center_lock, data_lock;
};
} // ns pt_impl