src/corosio/src/signal_set.cpp
100.0% Lines (22/22)
100.0% Functions (9/9)
src/corosio/src/signal_set.cpp
| Line | 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 | #include <boost/corosio/signal_set.hpp> | |
| 11 | #include <boost/corosio/detail/platform.hpp> | |
| 12 | ||
| 13 | #if BOOST_COROSIO_HAS_IOCP | |
| 14 | #include <boost/corosio/native/detail/iocp/win_signals.hpp> | |
| 15 | #elif BOOST_COROSIO_POSIX | |
| 16 | #include <boost/corosio/native/detail/posix/posix_signal_service.hpp> | |
| 17 | #endif | |
| 18 | ||
| 19 | namespace boost::corosio { | |
| 20 | namespace { | |
| 21 | ||
| 22 | #if BOOST_COROSIO_HAS_IOCP | |
| 23 | using signal_service = detail::win_signals; | |
| 24 | #elif BOOST_COROSIO_POSIX | |
| 25 | using signal_service = detail::posix_signal_service; | |
| 26 | #endif | |
| 27 | ||
| 28 | } // namespace | |
| 29 | ||
| 30 | // Defined here (not inline) so shared-library builds have a single | |
| 31 | // signal_state instance. With -fvisibility-inlines-hidden the inline | |
| 32 | // version would give each DSO its own static, causing use-after-free | |
| 33 | // when constructor and destructor run in different DSOs. | |
| 34 | ||
| 35 | #if BOOST_COROSIO_HAS_IOCP | |
| 36 | namespace detail::signal_detail { | |
| 37 | ||
| 38 | signal_state* | |
| 39 | get_signal_state() | |
| 40 | { | |
| 41 | static signal_state state; | |
| 42 | return &state; | |
| 43 | } | |
| 44 | ||
| 45 | } // namespace detail::signal_detail | |
| 46 | #elif BOOST_COROSIO_POSIX | |
| 47 | namespace detail::posix_signal_detail { | |
| 48 | ||
| 49 | signal_state* | |
| 50 | 890 | get_signal_state() |
| 51 | { | |
| 52 | static signal_state state; | |
| 53 | 890 | return &state; |
| 54 | } | |
| 55 | ||
| 56 | } // namespace detail::posix_signal_detail | |
| 57 | #endif | |
| 58 | ||
| 59 | 90 | signal_set::~signal_set() = default; |
| 60 | ||
| 61 | 88 | signal_set::signal_set(capy::execution_context& ctx) |
| 62 | 88 | : io_signal_set(create_handle<signal_service>(ctx)) |
| 63 | { | |
| 64 | 88 | } |
| 65 | ||
| 66 | 2 | signal_set::signal_set(signal_set&& other) noexcept |
| 67 | 2 | : io_signal_set(std::move(other)) |
| 68 | { | |
| 69 | 2 | } |
| 70 | ||
| 71 | signal_set& | |
| 72 | 4 | signal_set::operator=(signal_set&& other) noexcept |
| 73 | { | |
| 74 | 4 | if (this != &other) |
| 75 | 4 | h_ = std::move(other.h_); |
| 76 | 4 | return *this; |
| 77 | } | |
| 78 | ||
| 79 | void | |
| 80 | 12 | signal_set::do_cancel() |
| 81 | { | |
| 82 | 12 | get().cancel(); |
| 83 | 12 | } |
| 84 | ||
| 85 | std::error_code | |
| 86 | 96 | signal_set::add(int signal_number, flags_t flags) |
| 87 | { | |
| 88 | 96 | return get().add(signal_number, flags); |
| 89 | } | |
| 90 | ||
| 91 | std::error_code | |
| 92 | 4 | signal_set::remove(int signal_number) |
| 93 | { | |
| 94 | 4 | return get().remove(signal_number); |
| 95 | } | |
| 96 | ||
| 97 | std::error_code | |
| 98 | 4 | signal_set::clear() |
| 99 | { | |
| 100 | 4 | return get().clear(); |
| 101 | } | |
| 102 | ||
| 103 | } // namespace boost::corosio | |
| 104 |