Files
zoneminder/src/zm_poll_thread.cpp
Isaac Connor ed6cb8de88 fix: call Stop() before restarting in PollThread::Start()
Prevents potential deadlock by ensuring any running thread is signaled
to terminate before joining, matching the pattern used in other thread
classes.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 12:13:29 -05:00

34 lines
713 B
C++

#include "zm_poll_thread.h"
#include "zm_logger.h"
#include "zm_monitor.h"
#include "zm_signal.h"
PollThread::PollThread(Monitor *monitor) :
monitor_(monitor), terminate_(false) {
thread_ = std::thread(&PollThread::Run, this);
}
PollThread::~PollThread() {
Stop();
}
void PollThread::Start() {
Stop(); // Signal any running thread to terminate first
if (thread_.joinable()) thread_.join();
terminate_ = false;
Debug(3, "Starting polling thread");
thread_ = std::thread(&PollThread::Run, this);
}
void PollThread::Stop() {
terminate_ = true;
if (thread_.joinable()) {
thread_.join();
}
}
void PollThread::Run() {
while (!(terminate_ or zm_terminate)) {
monitor_->Poll();
}
}