YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
wait_until.hpp
Go to the documentation of this file.
1#pragma once
2
6
7#include <chrono>
8#include <cstddef>
9
10namespace yaclib {
11
12/**
13 * Wait until specified time has been reached or \ref Ready becomes true
14 *
15 * The behavior is undefined if \ref Valid is false before the call to this function.
16 * This function may block for longer than until after timeout_time has been reached
17 * due to scheduling or resource contention delays.
18 * \param timeout_time maximum time point to block until
19 * \param fs futures to wait
20 * \return The result of \ref Ready upon exiting
21 */
22template <typename Event = detail::MutexEvent, typename Clock, typename Duration, typename... Waited>
24 const std::chrono::time_point<Clock, Duration>& timeout_time, Waited&... fs) noexcept {
25 YACLIB_ASSERT(... && fs.Valid());
26 return detail::WaitCore<Event>(timeout_time, fs.GetHandle()...);
27}
28
29/**
30 * Wait until specified time has been reached or \ref Ready becomes true
31 *
32 * The behavior is undefined if \ref Valid is false before the call to this function.
33 * This function may block for longer than until after timeout_time has been reached
34 * due to scheduling or resource contention delays.
35 * \param timeout_time maximum time point to block until
36 * \param begin iterator to futures to wait
37 * \param end iterator to futures to wait
38 * \return The result of \ref Ready upon exiting
39 */
40template <typename Event = detail::MutexEvent, typename Clock, typename Duration, typename It, typename Sentinel,
41 typename = std::enable_if_t<is_input_range_pair_v<It, Sentinel> &&
43YACLIB_INLINE bool WaitUntil(const std::chrono::time_point<Clock, Duration>& timeout_time, It begin,
44 Sentinel end) noexcept {
45 static_assert(
47 "Use WaitUntil(timeout, begin, std::distance(begin, end)) instead"); // We don't use std::distance because we want
48 // to alert the user to the fact that it can
49 // be expensive.
50
51 return WaitUntil<Event, Clock, Duration>(timeout_time, begin, static_cast<std::size_t>(end - begin));
52}
53
54/**
55 * Wait until specified time has been reached or \ref Ready becomes true
56 *
57 * The behavior is undefined if \ref Valid is false before the call to this function.
58 * This function may block for longer than until after timeout_time has been reached
59 * due to scheduling or resource contention delays.
60 * \param timeout_time maximum time point to block until
61 * \param range of futures to wait
62 * \return The result of \ref Ready upon exiting
63 */
64template <typename Event = detail::MutexEvent, typename Clock, typename Duration, typename Range,
65 typename = std::enable_if_t<
68YACLIB_INLINE bool WaitUntil(const std::chrono::time_point<Clock, Duration>& timeout_time, Range&& range) noexcept {
69 return WaitUntil<Event, Clock, Duration>(timeout_time, std::begin(range), std::end(range));
70}
71
72/**
73 * Wait until specified time has been reached or \ref Ready becomes true
74 *
75 * The behavior is undefined if \ref Valid is false before the call to this function.
76 * This function may block for longer than until after timeout_time has been reached
77 * due to scheduling or resource contention delays.
78 * \param timeout_time maximum time point to block until
79 * \param begin iterator to futures to wait
80 * \param count of futures to wait
81 * \return The result of \ref Ready upon exiting
82 */
83template <typename Event = detail::MutexEvent, typename Clock, typename Duration, typename It,
84 typename = std::enable_if_t<is_input_iterator_v<It> &&
86YACLIB_INLINE bool WaitUntil(const std::chrono::time_point<Clock, Duration>& timeout_time, It begin,
87 std::size_t count) noexcept {
88 return detail::WaitIterator<Event>(timeout_time, begin, count);
89}
90
91} // namespace yaclib
#define YACLIB_ASSERT(cond)
Definition log.hpp:85
Contract< V, T > MakeContract()
Creates related future and promise.
Definition contract.hpp:25
YACLIB_INLINE std::enable_if_t<(... &&is_waitable_with_timeout_v< Waited >), bool > WaitUntil(const std::chrono::time_point< Clock, Duration > &timeout_time, Waited &... fs) noexcept
Wait until specified time has been reached or Ready becomes true.