From c06048a7af347bf843bf25bd305cbbf4d6cec266 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 21 Feb 2019 19:29:28 +0100 Subject: do less global memory fences in atomics --- pose-widget/pose-widget.cpp | 9 ++++----- pose-widget/pose-widget.hpp | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'pose-widget') 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_vec; - std::atomic fresh{false}; + std::atomic fresh = false; static constexpr int w = 320, h = 240; }; -- cgit v1.2.3