4 #include <boost/asio/execution_context.hpp>
5 #include <boost/intrusive/list.hpp>
7 namespace nexus::quic::detail {
10 using service_list_base_hook = boost::intrusive::list_base_hook<
11 boost::intrusive::tag<service_tag>>;
23 template <
typename IoObject>
24 class service :
public boost::asio::execution_context::service {
25 using base_hook = boost::intrusive::base_hook<service_list_base_hook>;
26 boost::intrusive::list<IoObject, base_hook> entries;
30 void shutdown()
override {
31 while (!entries.empty()) {
32 auto& entry = entries.front();
34 entry.service_shutdown();
38 using key_type = service;
39 static inline boost::asio::execution_context::id id;
41 explicit service(boost::asio::execution_context& ctx)
42 : boost::asio::execution_context::service(ctx) {}
45 void add(IoObject& entry) {
46 auto lock = std::scoped_lock{mutex};
47 entries.push_back(entry);
50 void remove(IoObject& entry) {
51 auto lock = std::scoped_lock{mutex};
52 if (entries.empty()) {
55 entries.erase(entries.iterator_to(entry));