src/corosio/src/signal_set.cpp
100.0% Lines (23/23)
100.0% Functions (9/9)
71.4% Branches (5/7)
| Line | Branch | 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 | #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 | 660 | get_signal_state() | ||
| 40 | { | |||
| 41 |
3/4✓ Branch 2 → 3 taken 27 times.
✓ Branch 2 → 8 taken 633 times.
✓ Branch 4 → 5 taken 27 times.
✗ Branch 4 → 8 not taken.
|
660 | static signal_state state; | |
| 42 | 660 | 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 | get_signal_state() | |||
| 51 | { | |||
| 52 | static signal_state state; | |||
| 53 | return &state; | |||
| 54 | } | |||
| 55 | ||||
| 56 | } // namespace detail::posix_signal_detail | |||
| 57 | #endif | |||
| 58 | ||||
| 59 | 36 | signal_set::~signal_set() = default; | ||
| 60 | ||||
| 61 | 35 | signal_set::signal_set(capy::execution_context& ctx) | ||
| 62 |
1/1✓ Branch 2 → 3 taken 35 times.
|
35 | : io_signal_set(create_handle<signal_service>(ctx)) | |
| 63 | { | |||
| 64 | 35 | } | ||
| 65 | ||||
| 66 | 1 | signal_set::signal_set(signal_set&& other) noexcept | ||
| 67 | 1 | : io_signal_set(std::move(other)) | ||
| 68 | { | |||
| 69 | 1 | } | ||
| 70 | ||||
| 71 | signal_set& | |||
| 72 | 2 | signal_set::operator=(signal_set&& other) noexcept | ||
| 73 | { | |||
| 74 |
1/2✓ Branch 2 → 3 taken 2 times.
✗ Branch 2 → 5 not taken.
|
2 | if (this != &other) | |
| 75 | 2 | h_ = std::move(other.h_); | ||
| 76 | 2 | return *this; | ||
| 77 | } | |||
| 78 | ||||
| 79 | void | |||
| 80 | 6 | signal_set::do_cancel() | ||
| 81 | { | |||
| 82 | 6 | get().cancel(); | ||
| 83 | 6 | } | ||
| 84 | ||||
| 85 | std::error_code | |||
| 86 | 34 | signal_set::add(int signal_number, flags_t flags) | ||
| 87 | { | |||
| 88 | 34 | return get().add(signal_number, flags); | ||
| 89 | } | |||
| 90 | ||||
| 91 | std::error_code | |||
| 92 | 2 | signal_set::remove(int signal_number) | ||
| 93 | { | |||
| 94 | 2 | return get().remove(signal_number); | ||
| 95 | } | |||
| 96 | ||||
| 97 | std::error_code | |||
| 98 | 2 | signal_set::clear() | ||
| 99 | { | |||
| 100 | 2 | return get().clear(); | ||
| 101 | } | |||
| 102 | ||||
| 103 | } // namespace boost::corosio | |||
| 104 |