diff options
-rw-r--r-- | options/scoped.cpp | 2 | ||||
-rw-r--r-- | pose-widget/pose-widget.cpp | 9 | ||||
-rw-r--r-- | pose-widget/pose-widget.hpp | 2 | ||||
-rw-r--r-- | proto-simconnect/ftnoir_protocol_sc.cpp | 2 | ||||
-rw-r--r-- | tracker-pt/ftnoir_tracker_pt.cpp | 8 | ||||
-rw-r--r-- | video/video-widget.cpp | 20 |
6 files changed, 21 insertions, 22 deletions
diff --git a/options/scoped.cpp b/options/scoped.cpp index ef5b94d6..f5e219e2 100644 --- a/options/scoped.cpp +++ b/options/scoped.cpp @@ -10,7 +10,7 @@ namespace options { // XXX hack: the flag shouldn't be here as action at distance -sh 20160926 -static std::atomic<bool> teardown_flag{false}; +static std::atomic<bool> teardown_flag = false; [[nodiscard]] static bool set_teardown_flag(bool value); static void ensure_thread(); static bool is_tracker_teardown(); diff --git a/pose-widget/pose-widget.cpp b/pose-widget/pose-widget.cpp index 943fc0ad..e9bf1d01 100644 --- a/pose-widget/pose-widget.cpp +++ b/pose-widget/pose-widget.cpp @@ -62,7 +62,7 @@ void pose_transform::run() { lock_guard l(mtx); - if (fresh) + if (fresh.load(std::memory_order_relaxed)) goto end; rotation = rotation_; @@ -88,8 +88,7 @@ void pose_widget::rotate_async(double xAngle, double yAngle, double zAngle, doub if (!check_is_visible()) return; - bool expected = true; - if (xform.fresh.compare_exchange_weak(expected, false)) + if (bool X = true; xform.fresh.compare_exchange_weak(X, false, std::memory_order_relaxed)) { repaint(); xform.rotate_async(xAngle, yAngle, zAngle, x, y, z); @@ -266,7 +265,7 @@ void pose_transform::project_quad_texture() { lock_guard l(mtx2); image.swap(image2); - fresh = true; + fresh.store(true, std::memory_order_relaxed); return; } @@ -358,7 +357,7 @@ void pose_transform::project_quad_texture() { lock_guard l2(mtx2); image.swap(image2); - fresh = true; + fresh.store(true, std::memory_order_relaxed); } } diff --git a/pose-widget/pose-widget.hpp b/pose-widget/pose-widget.hpp index aa51957e..1e50b392 100644 --- a/pose-widget/pose-widget.hpp +++ b/pose-widget/pose-widget.hpp @@ -84,7 +84,7 @@ struct pose_transform final : QThread }; std::vector<uv_> uv_vec; - std::atomic<bool> fresh{false}; + std::atomic<bool> fresh = false; static constexpr int w = 320, h = 240; }; diff --git a/proto-simconnect/ftnoir_protocol_sc.cpp b/proto-simconnect/ftnoir_protocol_sc.cpp index 9a1db9b5..42cdf596 100644 --- a/proto-simconnect/ftnoir_protocol_sc.cpp +++ b/proto-simconnect/ftnoir_protocol_sc.cpp @@ -62,7 +62,7 @@ void simconnect::run() break; } - if (reconnect) + if (reconnect.load(std::memory_order_relaxed)) break; if (!SUCCEEDED(hr = simconnect_calldispatch(handle, event_handler, (void*)this))) diff --git a/tracker-pt/ftnoir_tracker_pt.cpp b/tracker-pt/ftnoir_tracker_pt.cpp index 4223da26..a1a0dc1c 100644 --- a/tracker-pt/ftnoir_tracker_pt.cpp +++ b/tracker-pt/ftnoir_tracker_pt.cpp @@ -70,7 +70,7 @@ void Tracker_PT::run() *preview_frame = *frame; point_extractor->extract_points(*frame, *preview_frame, points); - point_count = points.size(); + point_count.store(points.size(), std::memory_order_relaxed); const f fx = pt_camera_info::get_focal_length(info.fov, info.res_x, info.res_y); const bool success = points.size() >= PointModel::N_POINTS; @@ -86,7 +86,7 @@ void Tracker_PT::run() PointModel(s), info, s.dynamic_pose ? s.init_phase_timeout : 0); - ever_success = true; + ever_success.store(true, std::memory_order_relaxed); } QMutexLocker l2(&data_lock); @@ -146,7 +146,7 @@ module_status Tracker_PT::start_tracker(QFrame* video_frame) void Tracker_PT::data(double *data) { - if (ever_success) + if (ever_success.load(std::memory_order_relaxed)) { Affine X_CM; { @@ -196,7 +196,7 @@ bool Tracker_PT::center() int Tracker_PT::get_n_points() { - return int(point_count); + return (int)point_count.load(std::memory_order_relaxed); } bool Tracker_PT::get_cam_info(pt_camera_info& info) diff --git a/video/video-widget.cpp b/video/video-widget.cpp index e73d34db..fb380fc4 100644 --- a/video/video-widget.cpp +++ b/video/video-widget.cpp @@ -25,11 +25,10 @@ video_widget::video_widget(QWidget* parent) : QWidget(parent) void video_widget::update_image(const QImage& img) { - QMutexLocker l(&mtx); - - if (freshp) + if (freshp.load(std::memory_order_relaxed)) return; - freshp = true; + + QMutexLocker l(&mtx); unsigned nbytes = (unsigned)(img.bytesPerLine() * img.height()); vec.resize(nbytes); vec.shrink_to_fit(); @@ -37,6 +36,8 @@ void video_widget::update_image(const QImage& img) texture = QImage((const unsigned char*) vec.data(), img.width(), img.height(), img.bytesPerLine(), img.format()); texture.setDevicePixelRatio(devicePixelRatioF()); + + freshp.store(true, std::memory_order_relaxed); } void video_widget::paintEvent(QPaintEvent*) @@ -49,16 +50,15 @@ void video_widget::paintEvent(QPaintEvent*) void video_widget::update_and_repaint() { + if (!freshp.load(std::memory_order_relaxed)) + return; + if (!check_is_visible()) return; QMutexLocker l(&mtx); - - if (freshp) - { - freshp = false; - repaint(); - } + repaint(); + freshp.store(false, std::memory_order_relaxed); } void video_widget::resizeEvent(QResizeEvent*) |