diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2014-06-12 03:51:52 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2014-06-12 03:51:52 +0200 |
commit | f0790cee70bb95209f42ea54e2a96f17b02110d6 (patch) | |
tree | 1dc80f24eb136fbecff59768b082d941c2209a45 | |
parent | 7454496476ba17ea622781d280606161581c9544 (diff) |
Fix lock order reversal
-rw-r--r-- | FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp | 20 | ||||
-rw-r--r-- | FTNoIR_Tracker_PT/ftnoir_tracker_pt.h | 5 |
2 files changed, 12 insertions, 13 deletions
diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp index 787a5128..e3823291 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.cpp @@ -23,12 +23,13 @@ const float deg2rad = 1.0/rad2deg; //-----------------------------------------------------------------------------
Tracker::Tracker()
- : commands(0),
+ : mutex(QMutex::Recursive),
+ commands(0),
video_widget(NULL),
video_frame(NULL),
tracking_valid(false),
- need_apply(false),
- new_settings(nullptr)
+ new_settings(nullptr)
+
{
qDebug()<<"Tracker::Tracker";
}
@@ -115,21 +116,18 @@ void Tracker::run() }
void Tracker::apply(settings& s)
{
- QMutexLocker lock(&mutex);
- need_apply = true;
- // caller guarantees object lifetime
+ // caller guarantees object lifetime
new_settings = &s;
}
void Tracker::apply_inner()
{
- QMutexLocker lock(&mutex);
- if (!need_apply)
- return;
qDebug()<<"Tracker:: Applying settings";
- auto& s = *new_settings;
+ settings* tmp = new_settings;
+ if (tmp == nullptr)
+ return;
+ auto& s = *tmp;
new_settings = nullptr;
- need_apply = false;
camera.set_device_index(s.cam_index);
camera.set_res(s.cam_res_x, s.cam_res_y);
camera.set_fps(s.cam_fps);
diff --git a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.h b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.h index 47a9987b..190ed76a 100644 --- a/FTNoIR_Tracker_PT/ftnoir_tracker_pt.h +++ b/FTNoIR_Tracker_PT/ftnoir_tracker_pt.h @@ -25,6 +25,7 @@ #include <QMutexLocker>
#include <QTime>
#include <opencv2/opencv.hpp>
+#include <atomic>
#ifndef OPENTRACK_API
# include <boost/shared_ptr.hpp>
#else
@@ -82,10 +83,10 @@ protected: PTVideoWidget* video_widget;
QFrame* video_frame;
- bool tracking_valid, need_apply;
+ bool tracking_valid;
settings s;
- settings* new_settings;
+ std::atomic<settings*> new_settings;
Timer time;
};
|