ifw-daq  2.1.0-pre1
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_
rad::IoExecutor::get_io_context
boost::asio::io_context & get_io_context() noexcept
Not part of the boost::thread::executor concept.
Definition: ioExecutor.hpp:41
rad::IoExecutor::IoExecutor
IoExecutor(IoExecutor &&)=default
rad::IoExecutor
Adapts boost::asio::io_context into a compatible boost::thread Executor type.
Definition: ioExecutor.hpp:12
rad::IoExecutor::closed
bool closed()
Definition: ioExecutor.hpp:25
rad::IoExecutor::close
void close()
Definition: ioExecutor.hpp:22
rad::IoExecutor::IoExecutor
IoExecutor(IoExecutor const &)=delete
rad::IoExecutor::operator=
IoExecutor & operator=(IoExecutor &&)=default
rad
Definition: ioExecutor.hpp:6
rad::IoExecutor::operator=
IoExecutor & operator=(IoExecutor &)=delete
rad::IoExecutor::IoExecutor
IoExecutor(boost::asio::io_context &ctx)
Definition: ioExecutor.hpp:14
rad::IoExecutor::try_executing_one
bool try_executing_one()
Definition: ioExecutor.hpp:34
rad::IoExecutor::submit
void submit(Closure &&closure)
Definition: ioExecutor.hpp:30