5#include "Stroika/Foundation/Execution/TimeOutException.h"
16 BlockingQueue<T>::BlockingQueue (
const Containers::Queue<T>& useQueue)
19 Require (useQueue.empty ());
27 fConditionVariable_.MutateDataNotifyAll ([&,
this] () {
28 Require (not fEndOfInput_);
35 fConditionVariable_.MutateDataNotifyAll ([
this] () { fEndOfInput_ =
true; });
48 return fEndOfInput_ and fQueue_.
empty ();
56 if (optional<T> tmp = fQueue_.RemoveHeadIf ()) {
60 if (fEndOfInput_) [[unlikely]] {
61 Execution::Throw (Streams::EOFException::kThe);
64 (void)fConditionVariable_.wait_until (waitableLock, Time::Pin2SafeSeconds (waitTil),
65 [
this] () {
return fEndOfInput_ or not fQueue_.empty (); });
74 if (optional<T> tmp = fQueue_.RemoveHeadIf ()) {
80 if (Time::GetTickCount () > waitTil) {
83 (void)fConditionVariable_.wait_until (waitableLock, Time::Pin2SafeSeconds (waitTil),
84 [
this] () {
return fEndOfInput_ or not fQueue_.empty (); });
91 return fQueue_.HeadIf ();
97 return fQueue_.
empty ();
103 return fQueue_.
size ();
105 template <
typename T>
110 template <
typename T>
116 template <
typename T>
122 fConditionVariable_.release_and_notify_all (waitableLock);
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.
A Queue is a first-in-first-out (FIFO) data structure, where elements are arranged in well-ordered fa...
nonvirtual bool empty() const
nonvirtual size_t size() const
void ThrowTimeoutExceptionAfter(Time::TimePointSeconds afterTickCount, EXCEPTION &&exception2Throw)
Throw TimeOutException if the @Time::GetTickCount () is >= the given value.
unique_lock< MUTEX > LockType
lock_guard< MUTEX > QuickLockType