diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2017-04-06 01:53:59 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2017-04-06 04:21:41 +0200 |
commit | facfc0e2444e485d6e14b6b96462ef0acefb42c0 (patch) | |
tree | 298df22ddb9eb4c001521a9319f35e195e500905 /pose-widget/pose-widget.hpp | |
parent | 2d4570810c861606c38330d90137d856b8862d02 (diff) |
pose-widget: prevent races and serial execution
We actually need to use "mtx" with the condition variable and
copy the data to the worker thread's stack.
Also allow for synchronous pose update, for tracking stoppage.
Diffstat (limited to 'pose-widget/pose-widget.hpp')
-rw-r--r-- | pose-widget/pose-widget.hpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/pose-widget/pose-widget.hpp b/pose-widget/pose-widget.hpp index 4f50008e..7befe72d 100644 --- a/pose-widget/pose-widget.hpp +++ b/pose-widget/pose-widget.hpp @@ -16,6 +16,7 @@ #include <mutex> #include <condition_variable> +#include <atomic> #ifdef BUILD_POSE_WIDGET # define POSE_WIDGET_EXPORT Q_DECL_EXPORT @@ -46,9 +47,11 @@ class pose_transform final : private QThread friend class pose_widget; - void rotateBy(double xAngle, double yAngle, double zAngle, - double x, double y, double z, - const QSize& size); + void rotate_async(double xAngle, double yAngle, double zAngle, double x, double y, double z); + void rotate_sync(double xAngle, double yAngle, double zAngle, double x, double y, double z); + + template<typename F> + void with_rotate(F&& fun, double xAngle, double yAngle, double zAngle, double x, double y, double z); void run() override; @@ -61,10 +64,10 @@ class pose_transform final : private QThread static vec3 normal(const vec3& p1, const vec3& p2, const vec3& p3); - rmat rotation; - vec3 translation; + rmat rotation, rotation_; + vec3 translation, translation_; - std::condition_variable_any cvar; + std::condition_variable cvar; std::mutex mtx, mtx2; QWidget* dst; @@ -74,6 +77,8 @@ class pose_transform final : private QThread int width, height; + std::atomic_flag fresh; + static constexpr int w = 320, h = 240; }; @@ -82,8 +87,8 @@ class POSE_WIDGET_EXPORT pose_widget final : public QWidget public: pose_widget(QWidget *parent = nullptr); ~pose_widget(); - void rotateBy(double xAngle, double yAngle, double zAngle, - double x, double y, double z); + void rotate_async(double xAngle, double yAngle, double zAngle, double x, double y, double z); + void rotate_sync(double xAngle, double yAngle, double zAngle, double x, double y, double z); private: pose_transform xform; |