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