100.00% Lines (2/2)
100.00% Functions (1/1)
| TLA | Baseline | Branch | ||||||
|---|---|---|---|---|---|---|---|---|
| Line | Hits | Code | Line | Hits | Code | |||
| 1 | // | 1 | // | |||||
| 2 | // Copyright (c) 2026 Steve Gerbino | 2 | // Copyright (c) 2026 Steve Gerbino | |||||
| 3 | // Copyright (c) 2026 Michael Vandeberg | 3 | // Copyright (c) 2026 Michael Vandeberg | |||||
| 4 | // | 4 | // | |||||
| 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |||||
| 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |||||
| 7 | // | 7 | // | |||||
| 8 | // Official repository: https://github.com/cppalliance/corosio | 8 | // Official repository: https://github.com/cppalliance/corosio | |||||
| 9 | // | 9 | // | |||||
| 10 | 10 | |||||||
| 11 | #ifndef BOOST_COROSIO_WAIT_TRAITS_HPP | 11 | #ifndef BOOST_COROSIO_WAIT_TRAITS_HPP | |||||
| 12 | #define BOOST_COROSIO_WAIT_TRAITS_HPP | 12 | #define BOOST_COROSIO_WAIT_TRAITS_HPP | |||||
| 13 | 13 | |||||||
| 14 | #include <boost/corosio/detail/config.hpp> | 14 | #include <boost/corosio/detail/config.hpp> | |||||
| 15 | 15 | |||||||
| 16 | #include <concepts> | 16 | #include <concepts> | |||||
| 17 | 17 | |||||||
| 18 | namespace boost::corosio { | 18 | namespace boost::corosio { | |||||
| 19 | 19 | |||||||
| 20 | /** Controls how much of the remaining time a single underlying | 20 | /** Controls how much of the remaining time a single underlying | |||||
| 21 | steady-clock wait may cover before `Clock::now()` is re-read. | 21 | steady-clock wait may cover before `Clock::now()` is re-read. | |||||
| 22 | A larger value costs fewer wakeups; a smaller value bounds how | 22 | A larger value costs fewer wakeups; a smaller value bounds how | |||||
| 23 | late an adjustment of `Clock` ( e.g. a stepped time-of-day | 23 | late an adjustment of `Clock` ( e.g. a stepped time-of-day | |||||
| 24 | clock ) is observed. The default covers the full remaining | 24 | clock ) is observed. The default covers the full remaining | |||||
| 25 | duration, which is exact for clocks that advance in lockstep | 25 | duration, which is exact for clocks that advance in lockstep | |||||
| 26 | with the machine's monotonic clock. | 26 | with the machine's monotonic clock. | |||||
| 27 | 27 | |||||||
| 28 | @par Example | 28 | @par Example | |||||
| 29 | @par !example capped_traits | 29 | @par !example capped_traits | |||||
| 30 | 30 | |||||||
| 31 | @tparam Clock The clock type whose durations are converted. | 31 | @tparam Clock The clock type whose durations are converted. | |||||
| 32 | 32 | |||||||
| 33 | @see delay | 33 | @see delay | |||||
| 34 | */ | 34 | */ | |||||
| 35 | template<class Clock> | 35 | template<class Clock> | |||||
| 36 | struct wait_traits | 36 | struct wait_traits | |||||
| 37 | { | 37 | { | |||||
| 38 | /** Convert a remaining duration into a wait duration. | 38 | /** Convert a remaining duration into a wait duration. | |||||
| 39 | 39 | |||||||
| 40 | Should return a positive duration when @p d is positive; a | 40 | Should return a positive duration when @p d is positive; a | |||||
| 41 | non-positive result degrades to reactor-rate re-checking. | 41 | non-positive result degrades to reactor-rate re-checking. | |||||
| 42 | 42 | |||||||
| 43 | @pre Must not throw and must not block — invoked on the | 43 | @pre Must not throw and must not block — invoked on the | |||||
| 44 | `io_context`'s run thread, including from the timer | 44 | `io_context`'s run thread, including from the timer | |||||
| 45 | completion path. | 45 | completion path. | |||||
| 46 | 46 | |||||||
| 47 | @param d The remaining time until the deadline. | 47 | @param d The remaining time until the deadline. | |||||
| 48 | 48 | |||||||
| 49 | @return The duration the next underlying wait may cover. | 49 | @return The duration the next underlying wait may cover. | |||||
| 50 | */ | 50 | */ | |||||
| HITCBC | 51 | 5 | static typename Clock::duration to_wait_duration(typename Clock::duration d) | 51 | 5 | static typename Clock::duration to_wait_duration(typename Clock::duration d) | ||
| 52 | { | 52 | { | |||||
| HITCBC | 53 | 5 | return d; | 53 | 5 | return d; | ||
| 54 | } | 54 | } | |||||
| 55 | }; | 55 | }; | |||||
| 56 | 56 | |||||||
| 57 | /** Concept for wait-traits policies usable with `Clock`. | 57 | /** Concept for wait-traits policies usable with `Clock`. | |||||
| 58 | 58 | |||||||
| 59 | Satisfied when `Traits::to_wait_duration` accepts a | 59 | Satisfied when `Traits::to_wait_duration` accepts a | |||||
| 60 | `Clock::duration` and returns something convertible back to it. | 60 | `Clock::duration` and returns something convertible back to it. | |||||
| 61 | `Traits::to_wait_duration` is expected not to throw; the | 61 | `Traits::to_wait_duration` is expected not to throw; the | |||||
| 62 | requires-expression above does not enforce this. | 62 | requires-expression above does not enforce this. | |||||
| 63 | */ | 63 | */ | |||||
| 64 | template<class Traits, class Clock> | 64 | template<class Traits, class Clock> | |||||
| 65 | concept WaitTraits = requires(typename Clock::duration d) { | 65 | concept WaitTraits = requires(typename Clock::duration d) { | |||||
| 66 | { | 66 | { | |||||
| 67 | Traits::to_wait_duration(d) | 67 | Traits::to_wait_duration(d) | |||||
| 68 | } -> std::convertible_to<typename Clock::duration>; | 68 | } -> std::convertible_to<typename Clock::duration>; | |||||
| 69 | }; | 69 | }; | |||||
| 70 | 70 | |||||||
| 71 | } // namespace boost::corosio | 71 | } // namespace boost::corosio | |||||
| 72 | 72 | |||||||
| 73 | #endif | 73 | #endif | |||||