YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
wait.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <yaclib/config.hpp>
7
8#include <cstddef>
9
10namespace yaclib {
11
12/**
13 * Wait until \ref Ready becomes true
14 *
15 * \param fs one or more futures to wait
16 */
17template <typename Event = detail::DefaultEvent, typename... Waited>
18YACLIB_INLINE std::enable_if_t<(... && is_waitable_v<Waited>), void> Wait(Waited&... fs) noexcept {
19 YACLIB_ASSERT(... && fs.Valid());
20 detail::WaitCore<Event>(detail::NoTimeoutTag{}, fs.GetHandle()...);
21}
22
23/**
24 * Wait until \ref Ready becomes true
25 *
26 * \param begin iterator to futures to wait
27 * \param end iterator to futures to wait
28 */
29template <typename Event = detail::DefaultEvent, typename It, typename Sentinel,
30 typename = std::enable_if_t<is_input_range_pair_v<It, Sentinel> &&
32YACLIB_INLINE void Wait(It begin, Sentinel end) noexcept {
33 static_assert(
35 "Use Wait(begin, std::distance(begin, end)) instead"); // We don't use std::distance because we want to alert
36 // the user to the fact that it can be expensive.
37
38 Wait<Event>(begin, static_cast<std::size_t>(end - begin));
39}
40
41/**
42 * Wait until \ref Ready becomes true
43 *
44 * \param range of futures to wait
45 */
46template <
47 typename Event = detail::DefaultEvent, typename Range,
48 typename = std::enable_if_t<is_input_range_v<Range> &&
50YACLIB_INLINE void Wait(Range&& range) noexcept {
51 Wait<Event>(std::begin(range), std::end(range));
52}
53
54/**
55 * Wait until \ref Ready becomes true
56 *
57 * \param begin iterator to futures to wait
58 * \param count of futures to wait
59 */
60template <
61 typename Event = detail::DefaultEvent, typename It,
62 typename = std::enable_if_t<is_input_iterator_v<It> && is_waitable_v<typename std::iterator_traits<It>::reference>>>
63YACLIB_INLINE void Wait(It begin, std::size_t count) noexcept {
64 detail::WaitIterator<Event>(detail::NoTimeoutTag{}, begin, count);
65}
66
67} // namespace yaclib
#define YACLIB_ASSERT(cond)
Definition log.hpp:85
MutexEvent DefaultEvent
Contract< V, T > MakeContract()
Creates related future and promise.
Definition contract.hpp:25
YACLIB_INLINE std::enable_if_t<(... &&is_waitable_v< Waited >), void > Wait(Waited &... fs) noexcept
Wait until Ready becomes true.
Definition wait.hpp:18