DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
WorkerThread.hpp
Go to the documentation of this file.
1
16#ifndef UTILITIES_INCLUDE_UTILITIES_WORKERTHREAD_HPP_
17#define UTILITIES_INCLUDE_UTILITIES_WORKERTHREAD_HPP_
18
19#include "ers/ers.hpp"
20#include "logging/Logging.hpp" // NOTE: if ISSUES ARE DECLARED BEFORE include logging/Logging.hpp, TLOG_DEBUG<<issue wont work.
21
22#include <functional>
23#include <future>
24#include <list>
25#include <memory>
26#include <string>
27
28namespace dunedaq::utilities {
64{
65public:
72 explicit WorkerThread(std::function<void(std::atomic<bool>&)> do_work);
73
78 void start_working_thread(const std::string& name = "noname");
86
91 bool thread_running() const { return m_thread_running.load(); }
92
93 WorkerThread(const WorkerThread&) = delete;
97
98private:
99 std::atomic<bool> m_thread_running;
100 std::unique_ptr<std::jthread> m_working_thread;
101 std::function<void(std::atomic<bool>&)> m_do_work;
102};
103} // namespace dunedaq::utilities
104
105#endif // UTILITIES_INCLUDE_UTILITIES_WORKERTHREAD_HPP_
WorkerThread contains a thread which runs the do_work() function.
std::unique_ptr< std::jthread > m_working_thread
void stop_working_thread()
Stop the working thread.
WorkerThread(WorkerThread &&)=delete
WorkerThread is not move-constructible.
void start_working_thread(const std::string &name="noname")
Start the working thread (which executes the do_work() function)
WorkerThread & operator=(WorkerThread &&)=delete
WorkerThread is not move-assignable.
std::atomic< bool > m_thread_running
WorkerThread & operator=(const WorkerThread &)=delete
WorkerThread is not copy-assginable.
bool thread_running() const
Determine if the thread is currently running.
WorkerThread(const WorkerThread &)=delete
WorkerThread is not copy-constructible.
std::function< void(std::atomic< bool > &)> m_do_work
WorkerThread(std::function< void(std::atomic< bool > &)> do_work)
WorkerThread Constructor.