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