YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
yaclib::OneShotEvent Class Reference

This class useful to wait or co_await some event. More...

#include <one_shot_event.hpp>

Classes

struct  TimedWaiter
 Public only because Waiter is public. More...
 
struct  Waiter
 Waiter is public for advanced users. More...
 

Public Member Functions

bool TryAdd (Job &job) noexcept
 Add job to the MPSC event queue.
 
bool Ready () noexcept
 was or not Set
 
void Wait () noexcept
 Wait Call or Set immediately return if Event is Ready.
 
template<typename Rep , typename Period >
YACLIB_INLINE bool WaitFor (const std::chrono::duration< Rep, Period > &timeout_duration)
 WaitFor Call or Set immediately return if Event is Ready.
 
template<typename Clock , typename Duration >
YACLIB_INLINE bool WaitUntil (const std::chrono::time_point< Clock, Duration > &timeout_time)
 WaitUntil Call or Set immediately return if Event is Ready.
 
void Call () noexcept
 Get all jobs and Call them.
 
void Set () noexcept
 Prevent pushing new jobs and Call()
 
void Reset () noexcept
 Reinitializes OneShotEvent, semantically the same as *this = {};
 

Detailed Description

This class useful to wait or co_await some event.

In general it's MPSC pattern: Multi threads can call TryAdd/Wait/Await* Single thread can call Call or Set

Definition at line 27 of file one_shot_event.hpp.

Member Function Documentation

◆ Call()

void yaclib::OneShotEvent::Call ( )
noexcept

Get all jobs and Call them.

Definition at line 42 of file one_shot_event.cpp.

References yaclib::MakeContract().

◆ Ready()

bool yaclib::OneShotEvent::Ready ( )
noexcept

was or not Set

Definition at line 30 of file one_shot_event.cpp.

◆ Reset()

void yaclib::OneShotEvent::Reset ( )
noexcept

Reinitializes OneShotEvent, semantically the same as *this = {};

If you don't explicitly call this method, then after the first one, Wait will always return immediately.

Note
Not thread-safe!

Definition at line 50 of file one_shot_event.cpp.

References yaclib::MakeContract(), and YACLIB_ASSERT.

◆ Set()

void yaclib::OneShotEvent::Set ( )
noexcept

Prevent pushing new jobs and Call()

Definition at line 46 of file one_shot_event.cpp.

References yaclib::MakeContract().

Referenced by yaclib::OneShotEvent::Waiter::Call().

◆ TryAdd()

bool yaclib::OneShotEvent::TryAdd ( Job job)
noexcept

Add job to the MPSC event queue.

When Call or Set will be called also will be called job->Call

But only if TryAdd return true. It can return false if on Event already was called Set

Definition at line 18 of file one_shot_event.cpp.

References yaclib::MakeContract().

Referenced by Wait().

◆ Wait()

void yaclib::OneShotEvent::Wait ( )
noexcept

Wait Call or Set immediately return if Event is Ready.

Definition at line 34 of file one_shot_event.cpp.

References yaclib::detail::MutexEvent::Make(), yaclib::MakeContract(), and TryAdd().

◆ WaitFor()

template<typename Rep , typename Period >
YACLIB_INLINE bool yaclib::OneShotEvent::WaitFor ( const std::chrono::duration< Rep, Period > &  timeout_duration)
inline

WaitFor Call or Set immediately return if Event is Ready.

Definition at line 54 of file one_shot_event.hpp.

References yaclib::MakeContract().

◆ WaitUntil()

YACLIB_INLINE bool yaclib::OneShotEvent::WaitUntil ( const std::chrono::time_point< Clock, Duration > &  timeout_time)
inline

WaitUntil Call or Set immediately return if Event is Ready.

Definition at line 63 of file one_shot_event.hpp.

References yaclib::MakeContract().


The documentation for this class was generated from the following files: