|
DUNE-DAQ
DUNE Trigger and Data Acquisition software
|
WorkerThread contains a thread which runs the do_work() function. More...
#include <WorkerThread.hpp>
Public Member Functions | |
| WorkerThread (std::function< void(std::atomic< bool > &)> do_work) | |
| WorkerThread Constructor. | |
| void | start_working_thread (const std::string &name="noname") |
| Start the working thread (which executes the do_work() function) | |
| void | stop_working_thread () |
| Stop the working thread. | |
| bool | thread_running () const |
| Determine if the thread is currently running. | |
| WorkerThread (const WorkerThread &)=delete | |
| WorkerThread is not copy-constructible. | |
| WorkerThread & | operator= (const WorkerThread &)=delete |
| WorkerThread is not copy-assginable. | |
| WorkerThread (WorkerThread &&)=delete | |
| WorkerThread is not move-constructible. | |
| WorkerThread & | operator= (WorkerThread &&)=delete |
| WorkerThread is not move-assignable. | |
Private Attributes | |
| std::atomic< bool > | m_thread_running |
| std::unique_ptr< std::jthread > | m_working_thread |
| std::function< void(std::atomic< bool > &)> | m_do_work |
WorkerThread contains a thread which runs the do_work() function.
WorkerThread runs a given function in a std::jthread and allows that work function to be started and stopped via the start_working_thread() and stop_working_thread() methods, respectively. The work function takes a std::atomic<bool>& which indicates whether the thread should continue running, so a typical implementation of a work function is:
If your do_work function is a class member, you will need to wrap it with std::bind or a lambda to bind the implicit 'this' argument, eg
Definition at line 63 of file WorkerThread.hpp.
|
explicit |
WorkerThread Constructor.
| do_work | Function to be executed in the thread |
This constructor sets the defaults for the thread control variables
Definition at line 20 of file WorkerThread.cpp.
|
delete |
WorkerThread is not copy-constructible.
|
delete |
WorkerThread is not move-constructible.
|
delete |
WorkerThread is not copy-assginable.
|
delete |
WorkerThread is not move-assignable.
| void dunedaq::utilities::WorkerThread::start_working_thread | ( | const std::string & | name = "noname" | ) |
Start the working thread (which executes the do_work() function)
| ThreadingIssue | if the thread is already running |
Definition at line 28 of file WorkerThread.cpp.
| void dunedaq::utilities::WorkerThread::stop_working_thread | ( | ) |
Stop the working thread.
| ThreadingIssue | If the thread has not yet been started |
| ThreadingIssue | If the thread is not in the joinable state |
| ThreadingIssue | If an exception occurs during thread join |
Definition at line 47 of file WorkerThread.cpp.
|
inline |
Determine if the thread is currently running.
Definition at line 91 of file WorkerThread.hpp.
|
private |
Definition at line 101 of file WorkerThread.hpp.
|
private |
Definition at line 99 of file WorkerThread.hpp.
|
private |
Definition at line 100 of file WorkerThread.hpp.