From f9b93e343a6febd87d9ce184bfe18d3fa50ec45c Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 7 Jul 2025 11:52:59 -0400 Subject: [PATCH] MT#63171 add AmSessionProcessor::stopThreads Method to stop all AmSessionProcessor threads that have been created. Change-Id: Ib339c72c5f7b3372f1d611c0e77c08e2f21a65d7 --- core/AmSessionProcessor.cpp | 15 +++++++++++++++ core/AmSessionProcessor.h | 1 + core/sems.cpp | 5 +++++ 3 files changed, 21 insertions(+) diff --git a/core/AmSessionProcessor.cpp b/core/AmSessionProcessor.cpp index bff81f01..aa93741c 100644 --- a/core/AmSessionProcessor.cpp +++ b/core/AmSessionProcessor.cpp @@ -68,6 +68,21 @@ void AmSessionProcessor::addThreads(unsigned int num_threads) { DBG("now %zd session processor threads running\n", threads.size()); } +void AmSessionProcessor::stopThreads() +{ + std::lock_guard _l(threads_mut); + DBG("shutting down %zu session processor threads\n", threads.size()); + // two-pass: first request stop, then join and delete + for (auto it = threads.begin(); it != threads.end(); it++) + (*it)->stop(); + while (!threads.empty()) { + auto* thread = threads.back(); + threads.pop_back(); + thread->join(); + delete thread; + } +} + AmSessionProcessorThread::AmSessionProcessorThread() : events(this), runcond(false) diff --git a/core/AmSessionProcessor.h b/core/AmSessionProcessor.h index 472120f6..0a6c652a 100644 --- a/core/AmSessionProcessor.h +++ b/core/AmSessionProcessor.h @@ -50,6 +50,7 @@ class AmSessionProcessor { public: static AmSessionProcessorThread* getProcessorThread(); static void addThreads(unsigned int num_threads); + static void stopThreads(); }; struct AmSessionProcessorThreadAddEvent diff --git a/core/sems.cpp b/core/sems.cpp index b3c9d78d..edabc6ae 100644 --- a/core/sems.cpp +++ b/core/sems.cpp @@ -680,6 +680,11 @@ int main(int argc, char* argv[]) sd.stopping(); +#ifdef SESSION_THREADPOOL + INFO("Starting session processor threads\n"); + AmSessionProcessor::stopThreads(); +#endif + INFO("Disposing plug-ins\n"); AmPlugIn::dispose();