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
3
#include <
yaclib/async/detail/wait_impl.hpp
>
4
#include <
yaclib/async/future.hpp
>
5
#include <
yaclib/util/detail/mutex_event.hpp
>
6
7
#include <chrono>
8
#include <cstddef>
9
10
namespace
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
*/
22
template
<
typename
Event
= detail::MutexEvent,
typename
Clock
,
typename
Duration
,
typename
...
Waited
>
23
YACLIB_INLINE
std::enable_if_t<(... &&
is_waitable_with_timeout_v<Waited>
),
bool
>
WaitUntil
(
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
*/
40
template
<
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> &&
42
is_waitable_with_timeout_v<typename std::iterator_traits<It>::reference
>>>
43
YACLIB_INLINE
bool
WaitUntil
(
const
std::chrono::time_point<Clock, Duration>&
timeout_time
, It
begin
,
44
Sentinel
end
)
noexcept
{
45
static_assert
(
46
has_constant_time_distance_v<It, Sentinel>
,
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
*/
64
template
<
typename
Event
= detail::MutexEvent,
typename
Clock
,
typename
Duration
,
typename
Range
,
65
typename
= std::enable_if_t<
66
is_input_range_v<Range>
&&
67
is_waitable_with_timeout_v<typename std::iterator_traits<detail::RangeIterator<Range>
>::reference>>>
68
YACLIB_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
*/
83
template
<
typename
Event
= detail::MutexEvent,
typename
Clock
,
typename
Duration
,
typename
It,
84
typename
= std::enable_if_t<is_input_iterator_v<It> &&
85
is_waitable_with_timeout_v<typename std::iterator_traits<It>::reference
>>>
86
YACLIB_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
future.hpp
Event
YACLIB_ASSERT
#define YACLIB_ASSERT(cond)
Definition
log.hpp:85
mutex_event.hpp
yaclib
Definition
base_core.hpp:15
yaclib::MakeContract
Contract< V, T > MakeContract()
Creates related future and promise.
Definition
contract.hpp:25
yaclib::WaitUntil
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.
Definition
wait_until.hpp:23
wait_impl.hpp
include
yaclib
async
wait_until.hpp
Generated by
1.9.8