PROFINET IO Controller Stack 1.0.0
Modern C++ implementation of a PROFINET IO Controller stack
Loading...
Searching...
No Matches
AsioIoContextRunner.h
Go to the documentation of this file.
1
4
5#pragma once
6
7#include <asio.hpp>
8#include <thread>
9
10namespace profinet
11{
25
35{
36 public:
39 explicit AsioIoContextRunner(asio::io_context& ioContext)
41 workGuard(asio::make_work_guard(ioContext)),
42 thread([&]
43 {
44 ioContext.run();
45 })
46 {
47 }
48
51 {
52 workGuard.reset();
53 ioContext.stop();
54
55 if (thread.joinable())
56 {
57 thread.join();
58 }
59 }
60
63
64 private:
65 asio::io_context& ioContext;
66 asio::executor_work_guard<asio::io_context::executor_type> workGuard;
67 std::jthread thread;
68};
69
70} // namespace profinet
Keeps an Asio I/O context running on a dedicated worker thread.
AsioIoContextRunner(asio::io_context &ioContext)
Start running the supplied I/O context.
asio::executor_work_guard< asio::io_context::executor_type > workGuard
AsioIoContextRunner & operator=(const AsioIoContextRunner &)=delete
AsioIoContextRunner(const AsioIoContextRunner &)=delete
~AsioIoContextRunner()
Stop the worker thread.
Abstract interface for keeping an Asio I/O context running.
IAsioIoContextRunner(IAsioIoContextRunner &&)=delete
virtual ~IAsioIoContextRunner()=default
IAsioIoContextRunner & operator=(IAsioIoContextRunner &&)=delete
IAsioIoContextRunner(const IAsioIoContextRunner &)=delete
IAsioIoContextRunner & operator=(const IAsioIoContextRunner &)=delete