Kurlyk
Loading...
Searching...
No Matches
kurlyk::utils::EventQueue< T > Class Template Reference

A thread-safe event queue that supports blocking and non-blocking event retrieval. More...

#include <EventQueue.hpp>

Public Member Functions

void push_event (T &&event)
 Adds an event to the queue using move semantics.
 
void push_event (const T &event)
 Adds a copy of an event to the queue and notifies any waiting threads.
 
pop_event ()
 Removes and returns an event from the queue (blocks if the queue is empty).
 
bool has_events () const
 Checks if there are events in the queue.
 

Private Attributes

std::queue< T > m_events
 Queue to store events.
 
std::mutex m_mutex
 Mutex to protect queue access.
 
std::condition_variable m_cond_var
 Condition variable for blocking until events are available.
 

Detailed Description

template<class T>
class kurlyk::utils::EventQueue< T >

A thread-safe event queue that supports blocking and non-blocking event retrieval.

Definition at line 17 of file EventQueue.hpp.

Member Function Documentation

◆ has_events()

template<class T>
bool kurlyk::utils::EventQueue< T >::has_events ( ) const
inline

Checks if there are events in the queue.

Returns
true if the queue is not empty, otherwise false.

Definition at line 47 of file EventQueue.hpp.

◆ pop_event()

template<class T>
T kurlyk::utils::EventQueue< T >::pop_event ( )
inline

Removes and returns an event from the queue (blocks if the queue is empty).

Returns
The retrieved event.

Definition at line 37 of file EventQueue.hpp.

◆ push_event() [1/2]

template<class T>
void kurlyk::utils::EventQueue< T >::push_event ( const T & event)
inline

Adds a copy of an event to the queue and notifies any waiting threads.

Parameters
eventThe event to add to the queue.

Definition at line 29 of file EventQueue.hpp.

◆ push_event() [2/2]

template<class T>
void kurlyk::utils::EventQueue< T >::push_event ( T && event)
inline

Adds an event to the queue using move semantics.

Parameters
eventThe event to add to the queue.

Definition at line 21 of file EventQueue.hpp.

Member Data Documentation

◆ m_cond_var

template<class T>
std::condition_variable kurlyk::utils::EventQueue< T >::m_cond_var
private

Condition variable for blocking until events are available.

Definition at line 55 of file EventQueue.hpp.

◆ m_events

template<class T>
std::queue<T> kurlyk::utils::EventQueue< T >::m_events
private

Queue to store events.

Definition at line 53 of file EventQueue.hpp.

◆ m_mutex

template<class T>
std::mutex kurlyk::utils::EventQueue< T >::m_mutex
mutableprivate

Mutex to protect queue access.

Definition at line 54 of file EventQueue.hpp.


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