summaryrefslogtreecommitdiffhomepage
path: root/tracker-pt
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2021-10-18 06:13:12 +0200
committerStanislaw Halik <sthalik@misaki.pl>2021-10-18 06:13:30 +0200
commitf6e793af0dfde09e5dc5712c132fe6e4865738ef (patch)
treed95bff62601ef047897bd4fad0121a532e54d87d /tracker-pt
parent54430acd4fb00b55b618110f60a0803448b09b13 (diff)
tracker/pt: fix the deadlock even harder
Diffstat (limited to 'tracker-pt')
-rw-r--r--tracker-pt/ftnoir_tracker_pt.cpp32
-rw-r--r--tracker-pt/ftnoir_tracker_pt.h2
2 files changed, 25 insertions, 9 deletions
diff --git a/tracker-pt/ftnoir_tracker_pt.cpp b/tracker-pt/ftnoir_tracker_pt.cpp
index 84e66221..f980c30d 100644
--- a/tracker-pt/ftnoir_tracker_pt.cpp
+++ b/tracker-pt/ftnoir_tracker_pt.cpp
@@ -45,24 +45,38 @@ Tracker_PT::~Tracker_PT()
camera->stop();
}
-void Tracker_PT::run()
+bool Tracker_PT::check_camera()
{
- portable::set_curthread_name("tracker/pt");
-
- while(!isInterruptionRequested())
+ if (reopen_camera_flag)
{
- if (reopen_camera_flag)
+ reopen_camera_flag = false;
+ if (!camera || last_camera_name != s.camera_name)
{
- reopen_camera_flag = false;
+ // deadlock avoidance
+
+ decltype(camera) camera_;
{
QMutexLocker l(&camera_mtx);
- camera = nullptr;
+ camera_ = std::move(camera);
}
- auto camera_ = traits->make_camera();
+ camera_ = traits->make_camera();
if (!camera_ || !camera_->start(s))
- break;
+ return false;
camera = std::move(camera_);
+ last_camera_name = s.camera_name;
}
+ }
+ return true;
+}
+
+void Tracker_PT::run()
+{
+ portable::set_curthread_name("tracker/pt");
+
+ while(!isInterruptionRequested())
+ {
+ if (!check_camera())
+ break;
pt_camera_info info;
bool new_frame = false;
diff --git a/tracker-pt/ftnoir_tracker_pt.h b/tracker-pt/ftnoir_tracker_pt.h
index c9b87102..bb388d5c 100644
--- a/tracker-pt/ftnoir_tracker_pt.h
+++ b/tracker-pt/ftnoir_tracker_pt.h
@@ -49,10 +49,12 @@ struct Tracker_PT : QThread, ITracker
private:
void run() override;
+ [[nodiscard]] bool check_camera();
pointer<pt_runtime_traits> traits;
mutable QRecursiveMutex camera_mtx;
+ QString last_camera_name;
PointTracker point_tracker;