19dunedaq::utilities::WorkerThread::WorkerThread(std::function<
void(std::atomic<bool>&)> do_work)
20 : m_thread_running(false)
21 , m_working_thread(nullptr)
27dunedaq::utilities::WorkerThread::start_working_thread(
const std::string& name)
29 if (thread_running()) {
31 "Attempted to start working thread "
32 "when it is already running!");
34 m_thread_running =
true;
35 m_working_thread = std::make_unique<std::jthread>([&] { m_do_work(std::ref(m_thread_running)); });
36 auto handle = m_working_thread->native_handle();
37 auto rc = pthread_setname_np(handle, name.c_str());
40 s <<
"The name " << name <<
" provided for the thread is too long.";
46dunedaq::utilities::WorkerThread::stop_working_thread()
48 if (!thread_running()) {
50 "Attempted to stop working thread "
51 "when it is not running!");
53 m_thread_running =
false;
55 if (m_working_thread->joinable()) {
57 m_working_thread->join();
58 }
catch (std::system_error
const& e) {
59 throw ThreadingIssue(
ERS_HERE, std::string(
"Error while joining thread, ") + e.what());
62 throw ThreadingIssue(
ERS_HERE,
"Thread not in joinable state during working thread stop!");
void warning(const Issue &issue)