ifw-daq  3.0.0-pre2
IFW Data Acquisition modules
ioExecutor.hpp
Go to the documentation of this file.
1 #ifndef RAD_IO_EXECUTOR_HPP_
2 #define RAD_IO_EXECUTOR_HPP_
3 // GCOVR_EXCL_START
4 #include <boost/asio/io_context.hpp>
5 
6 namespace rad {
7 
8 /**
9 * Adapts boost::asio::io_context into a compatible boost::thread Executor type.
10 * This must match boost::thread Executor concept.
11 */
12 class IoExecutor {
13  public:
14  explicit IoExecutor(boost::asio::io_context& ctx) : m_io_context(&ctx) {}
15  IoExecutor(IoExecutor&&) = default;
17  IoExecutor(IoExecutor const&) = delete;
19 
20 
21 
22  void close() { // NOLINT
23  m_io_context->stop();
24  }
25  bool closed() { // NOLINT
26  return m_io_context->stopped();
27  }
28 
29  template <typename Closure>
30  void submit(Closure&& closure) { // NOLINT
31  return m_io_context->post(std::move(closure));
32  }
33 
34  bool try_executing_one() { // NOLINT
35  return m_io_context->poll_one();
36  }
37 
38  /**
39  * Not part of the boost::thread::executor concept.
40  */
41  boost::asio::io_context& get_io_context() noexcept { // NOLINT
42  return *m_io_context;
43  }
44  private:
45  boost::asio::io_context* m_io_context;
46 };
47 
48 }
49 // GCOVR_EXCL_STOP
50 #endif // #ifndef RAD_IO_EXECUTOR_HPP_
Adapts boost::asio::io_context into a compatible boost::thread Executor type.
Definition: ioExecutor.hpp:12
bool try_executing_one()
Definition: ioExecutor.hpp:34
IoExecutor(boost::asio::io_context &ctx)
Definition: ioExecutor.hpp:14
IoExecutor(IoExecutor const &)=delete
IoExecutor & operator=(IoExecutor &)=delete
IoExecutor & operator=(IoExecutor &&)=default
boost::asio::io_context & get_io_context() noexcept
Not part of the boost::thread::executor concept.
Definition: ioExecutor.hpp:41
void submit(Closure &&closure)
Definition: ioExecutor.hpp:30
IoExecutor(IoExecutor &&)=default