include/boost/corosio/native/detail/posix/posix_signal.hpp

100.0% Lines (13/13) 100.0% List of functions (3/3) -% Branches (0/0)
posix_signal.hpp
f(x) Functions (3)
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/corosio/detail/continuation_op.hpp>
22 #include <boost/capy/ex/executor_ref.hpp>
23
24 #include <coroutine>
25 #include <cstddef>
26 #include <stop_token>
27 #include <system_error>
28
29 namespace boost::corosio {
30
31 namespace detail {
32
33 // Forward declarations
34 class posix_signal_service;
35
36 // Maximum signal number supported (NSIG is typically 64 on Linux)
37 enum
38 {
39 max_signal_number = 64
40 };
41
42 // signal_op - pending wait operation
43
44 94x struct signal_op : scheduler_op
45 {
46 std::coroutine_handle<> h;
47 detail::continuation_op cont_op;
48 capy::executor_ref d;
49 94x std::error_code* ec_out = nullptr;
50 94x int* signal_out = nullptr;
51 94x int signal_number = 0;
52 94x posix_signal_service* svc = nullptr; // For work_finished callback
53
54 void operator()() override;
55 void destroy() override;
56 };
57
58 // signal_registration - per-signal registration tracking
59
60 86x struct signal_registration
61 {
62 86x int signal_number = 0;
63 86x signal_set::flags_t flags = signal_set::none;
64 86x signal_set::implementation* owner = nullptr;
65 86x std::size_t undelivered = 0;
66 86x signal_registration* next_in_table = nullptr;
67 86x signal_registration* prev_in_table = nullptr;
68 86x signal_registration* next_in_set = nullptr;
69 };
70
71 // posix_signal - per-signal_set implementation
72
73 class posix_signal final
74 : public signal_set::implementation
75 , public intrusive_list<posix_signal>::node
76 {
77 friend class posix_signal_service;
78
79 posix_signal_service& svc_;
80 signal_registration* signals_ = nullptr;
81 signal_op pending_op_;
82 bool waiting_ = false;
83
84 public:
85 explicit posix_signal(posix_signal_service& svc) noexcept;
86
87 std::coroutine_handle<> wait(
88 std::coroutine_handle<>,
89 capy::executor_ref,
90 std::stop_token,
91 std::error_code*,
92 int*) override;
93
94 std::error_code add(int signal_number, signal_set::flags_t flags) override;
95 std::error_code remove(int signal_number) override;
96 std::error_code clear() override;
97 void cancel() override;
98 };
99
100 } // namespace detail
101
102 } // namespace boost::corosio
103
104 #endif // BOOST_COROSIO_POSIX
105
106 #endif // BOOST_COROSIO_NATIVE_DETAIL_POSIX_POSIX_SIGNAL_HPP
107