replay: fix hangs on exit (#32795)

fix hang on exit
old-commit-hash: 776b08d561ebdfa9bd12e92b57ab0770f4a4b4a3
This commit is contained in:
Dean Lee
2024-06-20 15:16:14 +08:00
committed by GitHub
parent 5ce4ea7a77
commit 1133898f68
2 changed files with 12 additions and 5 deletions

View File

@@ -27,6 +27,13 @@ CameraServer::CameraServer(std::pair<int, int> camera_size[MAX_CAMERAS]) {
CameraServer::~CameraServer() {
for (auto &cam : cameras_) {
if (cam.thread.joinable()) {
// Clear the queue
std::pair<FrameReader*, const Event *> item;
while (cam.queue.try_pop(item)) {
--publishing_;
}
// Signal termination and join the thread
cam.queue.push({});
cam.thread.join();
}

View File

@@ -50,20 +50,20 @@ Replay::~Replay() {
}
void Replay::stop() {
if (!stream_thread_ && segments_.empty()) return;
rInfo("shutdown: in progress...");
exit_ = true;
if (stream_thread_ != nullptr) {
exit_ = true;
rInfo("shutdown: in progress...");
pauseStreamThread();
stream_cv_.notify_one();
stream_thread_->quit();
stream_thread_->wait();
stream_thread_->deleteLater();
stream_thread_ = nullptr;
rInfo("shutdown: done");
}
timeline_future.waitForFinished();
rInfo("shutdown: done");
camera_server_.reset(nullptr);
segments_.clear();
}
bool Replay::load() {