include/boost/corosio/native/detail/posix/posix_signal.hpp
100.0% Lines (13/13)
100.0% Functions (3/3)
-% Branches (0/0)
| Line | TLA | Hits | Source Code |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2026 Steve Gerbino | ||
| 3 | // | ||
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
| 6 | // | ||
| 7 | // Official repository: https://github.com/cppalliance/corosio | ||
| 8 | // | ||
| 9 | |||
| 10 | #ifndef BOOST_COROSIO_NATIVE_DETAIL_POSIX_POSIX_SIGNAL_HPP | ||
| 11 | #define BOOST_COROSIO_NATIVE_DETAIL_POSIX_POSIX_SIGNAL_HPP | ||
| 12 | |||
| 13 | #include <boost/corosio/detail/platform.hpp> | ||
| 14 | |||
| 15 | #if BOOST_COROSIO_POSIX | ||
| 16 | |||
| 17 | #include <boost/corosio/detail/config.hpp> | ||
| 18 | #include <boost/corosio/signal_set.hpp> | ||
| 19 | #include <boost/corosio/detail/intrusive.hpp> | ||
| 20 | #include <boost/corosio/detail/scheduler_op.hpp> | ||
| 21 | #include <boost/capy/ex/executor_ref.hpp> | ||
| 22 | |||
| 23 | #include <coroutine> | ||
| 24 | #include <cstddef> | ||
| 25 | #include <stop_token> | ||
| 26 | #include <system_error> | ||
| 27 | |||
| 28 | namespace boost::corosio { | ||
| 29 | |||
| 30 | namespace detail { | ||
| 31 | |||
| 32 | // Forward declarations | ||
| 33 | class posix_signal_service; | ||
| 34 | |||
| 35 | // Maximum signal number supported (NSIG is typically 64 on Linux) | ||
| 36 | enum | ||
| 37 | { | ||
| 38 | max_signal_number = 64 | ||
| 39 | }; | ||
| 40 | |||
| 41 | // signal_op - pending wait operation | ||
| 42 | |||
| 43 | 94 | struct signal_op : scheduler_op | |
| 44 | { | ||
| 45 | std::coroutine_handle<> h; | ||
| 46 | capy::executor_ref d; | ||
| 47 | 94 | std::error_code* ec_out = nullptr; | |
| 48 | 94 | int* signal_out = nullptr; | |
| 49 | 94 | int signal_number = 0; | |
| 50 | 94 | posix_signal_service* svc = nullptr; // For work_finished callback | |
| 51 | |||
| 52 | void operator()() override; | ||
| 53 | void destroy() override; | ||
| 54 | }; | ||
| 55 | |||
| 56 | // signal_registration - per-signal registration tracking | ||
| 57 | |||
| 58 | 86 | struct signal_registration | |
| 59 | { | ||
| 60 | 86 | int signal_number = 0; | |
| 61 | 86 | signal_set::flags_t flags = signal_set::none; | |
| 62 | 86 | signal_set::implementation* owner = nullptr; | |
| 63 | 86 | std::size_t undelivered = 0; | |
| 64 | 86 | signal_registration* next_in_table = nullptr; | |
| 65 | 86 | signal_registration* prev_in_table = nullptr; | |
| 66 | 86 | signal_registration* next_in_set = nullptr; | |
| 67 | }; | ||
| 68 | |||
| 69 | // posix_signal - per-signal_set implementation | ||
| 70 | |||
| 71 | class posix_signal final | ||
| 72 | : public signal_set::implementation | ||
| 73 | , public intrusive_list<posix_signal>::node | ||
| 74 | { | ||
| 75 | friend class posix_signal_service; | ||
| 76 | |||
| 77 | posix_signal_service& svc_; | ||
| 78 | signal_registration* signals_ = nullptr; | ||
| 79 | signal_op pending_op_; | ||
| 80 | bool waiting_ = false; | ||
| 81 | |||
| 82 | public: | ||
| 83 | explicit posix_signal(posix_signal_service& svc) noexcept; | ||
| 84 | |||
| 85 | std::coroutine_handle<> wait( | ||
| 86 | std::coroutine_handle<>, | ||
| 87 | capy::executor_ref, | ||
| 88 | std::stop_token, | ||
| 89 | std::error_code*, | ||
| 90 | int*) override; | ||
| 91 | |||
| 92 | std::error_code add(int signal_number, signal_set::flags_t flags) override; | ||
| 93 | std::error_code remove(int signal_number) override; | ||
| 94 | std::error_code clear() override; | ||
| 95 | void cancel() override; | ||
| 96 | }; | ||
| 97 | |||
| 98 | } // namespace detail | ||
| 99 | |||
| 100 | } // namespace boost::corosio | ||
| 101 | |||
| 102 | #endif // BOOST_COROSIO_POSIX | ||
| 103 | |||
| 104 | #endif // BOOST_COROSIO_NATIVE_DETAIL_POSIX_POSIX_SIGNAL_HPP | ||
| 105 |