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.
pull/3151/head
Peter Keresztes Schmidt 2021-02-09 23:54:50 +01:00
parent 8fa1249b33
commit 0380bee130
3 changed files with 5 additions and 6 deletions

View File

@ -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()");

View File

@ -10,7 +10,8 @@ class AnalysisThread {
public:
explicit AnalysisThread(std::shared_ptr<Monitor> monitor);
~AnalysisThread();
AnalysisThread(AnalysisThread &&rhs) noexcept;
AnalysisThread(AnalysisThread &rhs) = delete;
AnalysisThread(AnalysisThread &&rhs) = delete;
private:
void Run();

View File

@ -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 <getopt.h>
#include <iostream>
@ -287,7 +288,7 @@ int main(int argc, char *argv[]) {
}
#endif
std::vector<AnalysisThread> analysis_threads = std::vector<AnalysisThread>();
std::vector<std::unique_ptr<AnalysisThread>> analysis_threads = std::vector<std::unique_ptr<AnalysisThread>>();
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<AnalysisThread>(monitors[i]));
}
#if HAVE_RTSP_SERVER
if ( rtsp_server_threads ) {