4#ifndef _Stroika_Foundation_Execution_WaitForIOReady_h_
5#define _Stroika_Foundation_Execution_WaitForIOReady_h_ 1
7#include "Stroika/Foundation/StroikaPreComp.h"
11#include "Stroika/Foundation/Common/Common.h"
12#include "Stroika/Foundation/Containers/Collection.h"
13#include "Stroika/Foundation/Containers/Set.h"
54#ifndef qStroika_Foundation_Execution_WaitForIOReady_UseStopTokenAbortWakeup
55#if defined(__cpp_lib_jthread)
56#define qStroika_Foundation_Execution_WaitForIOReady_UseStopTokenAbortWakeup 1
58#define qStroika_Foundation_Execution_WaitForIOReady_UseStopTokenAbortWakeup 0
76#ifndef qStroika_Foundation_Execution_WaitForIOReady_UsePPoll
77#if !qStroika_Foundation_Execution_WaitForIOReady_UseStopTokenAbortWakeup && defined(__linux__)
78#define qStroika_Foundation_Execution_WaitForIOReady_UsePPoll 1
80#define qStroika_Foundation_Execution_WaitForIOReady_UsePPoll 0
84 namespace WaitForIOReady_Support {
86#if !qStroika_Foundation_Execution_WaitForIOReady_UseStopTokenAbortWakeup && !qStroika_Foundation_Execution_WaitForIOReady_UsePPoll
124#if qStroika_Platform_Windows
125 using SDKPollableType = SOCKET;
132 class WaitForIOReady_Base {
145 enum class TypeOfMonitor {
178 static inline const TypeOfMonitorSet kDefaultTypeOfMonitor{TypeOfMonitor::eRead};
187 static auto _WaitQuietlyUntil (
const pair<SDKPollableType, TypeOfMonitorSet>* start,
const pair<SDKPollableType, TypeOfMonitorSet>* end,
208 virtual bool IsSet ()
const = 0;
211 virtual void Set () = 0;
214 virtual void Clear () = 0;
218 virtual pair<SDKPollableType, WaitForIOReady_Base::TypeOfMonitorSet> GetWaitInfo () = 0;
220 unique_ptr<EventFD> mkEventFD ();
222 template <
typename T>
223 struct WaitForIOReady_Traits {
227 using HighLevelType = T;
285 template <
typename T = WaitForIOReady_Support::SDKPollableType,
typename TRAITS = WaitForIOReady_Support::WaitForIOReady_Traits<T>>
286 class [[nodiscard]]
WaitForIOReady :
public WaitForIOReady_Support::WaitForIOReady_Base {
288 using TraitsType = TRAITS;
335 optional<pair<SDKPollableType, TypeOfMonitorSet>> pollable2Wakeup = nullopt);
337 optional<pair<SDKPollableType, TypeOfMonitorSet>> pollable2Wakeup = nullopt);
339 optional<pair<SDKPollableType, TypeOfMonitorSet>> pollable2Wakeup = nullopt);
367 nonvirtual Containers::Set<T> Wait (Time::DurationSeconds waitFor = Time::kInfinity);
381 nonvirtual Containers::Set<T> WaitQuietly (Time::DurationSeconds waitFor = Time::kInfinity);
395 nonvirtual Containers::Set<T> WaitUntil (Time::TimePointSeconds timeoutAt = Time::TimePointSeconds{Time::kInfinity});
417 const optional<pair<SDKPollableType, TypeOfMonitorSet>> fPollable2Wakeup_;
427#include "WaitForIOReady.inl"
#define Stroika_Define_Enum_Bounds(FIRST_ITEM, LAST_ITEM)
time_point< RealtimeClock, DurationSeconds > TimePointSeconds
TimePointSeconds is a simpler approach to chrono::time_point, which doesn't require using templates e...
chrono::duration< double > DurationSeconds
chrono::duration<double> - a time span (length of time) measured in seconds, but high precision.
#define Stroika_ATTRIBUTE_NO_UNIQUE_ADDRESS_VCFORCE
[[msvc::no_unique_address]] isn't always broken in MSVC. Annotate with this on things where its not b...
static Time::DurationSeconds sPollWaitChunkTime
Set<T> is a container of T, where once an item is added, additionally adds () do nothing.
NOT a real mutex - just a debugging infrastructure support tool so in debug builds can be assured thr...
WaitForIOReady(WaitForIOReady &&) noexcept=default
Copies and moves share the descriptors - none is duplicated.
Iterable<T> is a base class for containers which easily produce an Iterator<T> to traverse them.