From 0380bee130db5c141038ebceb528705936a9b1b3 Mon Sep 17 00:00:00 2001 From: Peter Keresztes Schmidt Date: Tue, 9 Feb 2021 23:54:50 +0100 Subject: [PATCH] AnalysisThread: Make the class un-movable We depend on an unchanged value of "this" after the creation of the thread otherwise undefined values would be accessed within the std::thread. --- src/zm_analysis_thread.cpp | 3 --- src/zm_analysis_thread.h | 3 ++- src/zmc.cpp | 5 +++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/zm_analysis_thread.cpp b/src/zm_analysis_thread.cpp index bc8f3c610..143f970ac 100644 --- a/src/zm_analysis_thread.cpp +++ b/src/zm_analysis_thread.cpp @@ -14,9 +14,6 @@ AnalysisThread::~AnalysisThread() { thread_.join(); } -AnalysisThread::AnalysisThread(AnalysisThread &&rhs) noexcept - : monitor_(std::move(rhs.monitor_)), terminate_(rhs.terminate_.load()), thread_(std::move(rhs.thread_)) {} - void AnalysisThread::Run() { Debug(2, "AnalysisThread::Run()"); diff --git a/src/zm_analysis_thread.h b/src/zm_analysis_thread.h index 7e82614ec..9c7a770f7 100644 --- a/src/zm_analysis_thread.h +++ b/src/zm_analysis_thread.h @@ -10,7 +10,8 @@ class AnalysisThread { public: explicit AnalysisThread(std::shared_ptr monitor); ~AnalysisThread(); - AnalysisThread(AnalysisThread &&rhs) noexcept; + AnalysisThread(AnalysisThread &rhs) = delete; + AnalysisThread(AnalysisThread &&rhs) = delete; private: void Run(); diff --git a/src/zmc.cpp b/src/zmc.cpp index 7c73db06f..9d0051e78 100644 --- a/src/zmc.cpp +++ b/src/zmc.cpp @@ -62,6 +62,7 @@ possible, this should run at more or less constant speed. #include "zm_rtsp_server_thread.h" #include "zm_signal.h" #include "zm_time.h" +#include "zm_utils.h" #include #include @@ -287,7 +288,7 @@ int main(int argc, char *argv[]) { } #endif - std::vector analysis_threads = std::vector(); + std::vector> analysis_threads = std::vector>(); int *capture_delays = new int[monitors.size()]; int *alarm_capture_delays = new int[monitors.size()]; @@ -303,7 +304,7 @@ int main(int argc, char *argv[]) { Monitor::Function function = monitors[0]->GetFunction(); if ( function != Monitor::MONITOR ) { Debug(1, "Starting an analysis thread for monitor (%d)", monitors[i]->Id()); - analysis_threads.emplace_back(monitors[i]); + analysis_threads.emplace_back(ZM::make_unique(monitors[i])); } #if HAVE_RTSP_SERVER if ( rtsp_server_threads ) {