4#include "TimeOutException.h"
13 template <
typename T,
typename TRAITS>
14 UpdatableWaitForIOReady<T, TRAITS>::UpdatableWaitForIOReady (
const Traversal::Iterable<pair<T, TypeOfMonitorSet>>& fds)
15 : fEventFD_{WaitForIOReady_Support::
mkEventFD ()}
16 , fPollable2Wakeup_{fEventFD_->GetWaitInfo ()}
20 template <
typename T,
typename TRAITS>
21 inline UpdatableWaitForIOReady<T, TRAITS>::UpdatableWaitForIOReady ()
22 : UpdatableWaitForIOReady{Traversal::Iterable<pair<T, TypeOfMonitorSet>>{}}
25 template <
typename T,
typename TRAITS>
26 UpdatableWaitForIOReady<T, TRAITS>::UpdatableWaitForIOReady (
const Traversal::Iterable<T>& fds,
const TypeOfMonitorSet& flags)
27 : UpdatableWaitForIOReady{
28 fds.template Map<Traversal::Iterable<pair<T, TypeOfMonitorSet>>> ([&] (const T& t) {
return make_pair (t, flags); })}
31 template <
typename T,
typename TRAITS>
32 UpdatableWaitForIOReady<T, TRAITS>::UpdatableWaitForIOReady (
const T& fd,
const TypeOfMonitorSet& flags)
33 : UpdatableWaitForIOReady{Containers::Collection<pair<T, TypeOfMonitorSet>>{make_pair (fd, flags)}}
36 template <
typename T,
typename TRAITS>
39 fData_.rwget ().
clear ();
42 template <
typename T,
typename TRAITS>
45 return fData_.load ();
47 template <
typename T,
typename TRAITS>
48 inline void UpdatableWaitForIOReady<T, TRAITS>::AddAll (
const Traversal::Iterable<T>& fds,
const TypeOfMonitorSet& flags)
51 auto lk = fData_.rwget ();
52 for (
const auto& i : fds) {
58 template <
typename T,
typename TRAITS>
59 inline void UpdatableWaitForIOReady<T, TRAITS>::AddAll (
const Traversal::Iterable<pair<T, TypeOfMonitorSet>>& fds)
61 fData_.rwget ()->fData_.AddAll (fds);
64 template <
typename T,
typename TRAITS>
65 inline auto UpdatableWaitForIOReady<T, TRAITS>::Wait (Time::DurationSeconds waitFor) -> Containers::Set<T>
67 return WaitUntil (waitFor + Time::GetTickCount ());
69 template <
typename T,
typename TRAITS>
70 inline auto UpdatableWaitForIOReady<T, TRAITS>::Wait (
const Time::Duration& waitFor) -> Containers::Set<T>
72 return WaitUntil (waitFor + Time::GetTickCount ());
74 template <
typename T,
typename TRAITS>
75 inline auto UpdatableWaitForIOReady<T, TRAITS>::WaitQuietly (Time::DurationSeconds waitFor) -> Containers::Set<T>
77 return WaitQuietlyUntil (waitFor + Time::GetTickCount ());
79 template <
typename T,
typename TRAITS>
80 inline auto UpdatableWaitForIOReady<T, TRAITS>::WaitQuietly (
const Time::Duration& waitFor) -> Containers::Set<T>
82 return WaitQuietly (waitFor);
84 template <
typename T,
typename TRAITS>
85 void UpdatableWaitForIOReady<T, TRAITS>::Add (T fd,
const TypeOfMonitorSet& flags)
87 fData_.rwget ()->Add (pair<T, TypeOfMonitorSet>{fd, flags});
90 template <
typename T,
typename TRAITS>
91 void UpdatableWaitForIOReady<T, TRAITS>::Remove ([[maybe_unused]] T fd)
93 if (fData_.rwget ()->RemoveIf ([&] (
auto p) { return p.first == fd; })) {
97 template <
typename T,
typename TRAITS>
98 void UpdatableWaitForIOReady<T, TRAITS>::RemoveAll ([[maybe_unused]]
const Traversal::Iterable<T>& fds)
100 Containers::Set<T> fdsSet{fds};
101 if (fData_.rwget ()->RemoveAll ([&] (
auto p) { return fdsSet.Contains (p.first); }) != 0) {
105 template <
typename T,
typename TRAITS>
106 void UpdatableWaitForIOReady<T, TRAITS>::SetDescriptors (
const Traversal::Iterable<pair<T, TypeOfMonitorSet>>& fds)
111 template <
typename T,
typename TRAITS>
112 void UpdatableWaitForIOReady<T, TRAITS>::SetDescriptors (
const Traversal::Iterable<T>& fds,
const TypeOfMonitorSet& flags)
114 SetDescriptors (fds.template Map<Traversal::Iterable<pair<T, TypeOfMonitorSet>>> ([&] (
const T& t) { return make_pair (t, flags); }));
116 template <
typename T,
typename TRAITS>
120 if (result.
empty ()) {
121 Execution::ThrowTimeoutExceptionAfter (timeoutAt);
125 template <
typename T,
typename TRAITS>
133 return mkWaiter_ ().WaitQuietlyUntil (timeoutAt);
135 template <
typename T,
typename TRAITS>
136 inline WaitForIOReady<T, TRAITS> UpdatableWaitForIOReady<T, TRAITS>::mkWaiter_ ()
141 auto dataLock = fData_.rwget ();
142 Iterable<pair<T, TypeOfMonitorSet>> r{dataLock.cref ()};
143 return WaitForIOReady<T, TRAITS>{r, fPollable2Wakeup_};
145 return WaitForIOReady<T, TRAITS>{fData_.load (), fPollable2Wakeup_};
time_point< RealtimeClock, DurationSeconds > TimePointSeconds
TimePointSeconds is a simpler approach to chrono::time_point, which doesn't require using templates e...
Set<T> is a container of T, where once an item is added, additionally adds () do nothing.
Simple wrapper on WaitForIOReady (POSIX select/poll/etc API) - except it allows for the list if polle...
Iterable<T> is a base class for containers which easily produce an Iterator<T> to traverse them.
nonvirtual bool empty() const
Returns true iff size() == 0.
unique_ptr< EventFD > mkEventFD()