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 {
29
30// Disable coverage collection LCOV_EXCL_START
34ERS_DECLARE_ISSUE(utilities, // Namespace
35 ThreadingIssue, // Issue Class Name
36 "Threading Issue detected: " << err, // Message
37 ((std::string)err)) // Message parameters
38// Re-enable coverage collection LCOV_EXCL_STOP
39
40namespace utilities {
75class WorkerThread
76{
77public:
84 explicit WorkerThread(std::function<void(std::atomic<bool>&)> do_work);
85
90 void start_working_thread(const std::string& name = "noname");
97 void stop_working_thread();
98
103 bool thread_running() const { return m_thread_running.load(); }
104
105 WorkerThread(const WorkerThread&) = delete;
106 WorkerThread& operator=(const WorkerThread&) = delete;
107 WorkerThread(WorkerThread&&) = delete;
108 WorkerThread& operator=(WorkerThread&&) = delete;
109
110private:
111 std::atomic<bool> m_thread_running;
112 std::unique_ptr<std::thread> m_working_thread;
113 std::function<void(std::atomic<bool>&)> m_do_work;
114};
115} // namespace utilities
116
117} // namespace dunedaq
118
119#endif // UTILITIES_INCLUDE_UTILITIES_WORKERTHREAD_HPP_
#define ERS_DECLARE_ISSUE(namespace_name, class_name, message, attributes)
Including Qt Headers.