sptk2 logo
SPTK Home Page
Public Types | Public Member Functions | List of all members
sptk::SynchronizedQueue< T > Class Template Reference

#include <SynchronizedQueue.h>

Public Types

using CallbackFunction = std::function< bool(T &item)>
 

Public Member Functions

void push (T &&data)
 
void push (const T &data)
 
bool pop (T &item, std::chrono::milliseconds timeout)
 
virtual void wakeup ()
 
bool empty () const
 
size_t size () const
 
void clear ()
 
bool each (const CallbackFunction &callbackFunction)
 

Detailed Description

template<class T>
class sptk::SynchronizedQueue< T >

Synchronized template queue

Simple thread-safe queue

Member Typedef Documentation

◆ CallbackFunction

template<class T >
using sptk::SynchronizedQueue< T >::CallbackFunction = std::function<bool(T& item)>

Queue callback function used in each() method.

Iterates through queue until false is returned.

Parameters
itemT&, List item
datavoid*, Optional function-specific data

Member Function Documentation

◆ clear()

template<class T >
void sptk::SynchronizedQueue< T >::clear ( )
inline

Removes all items from the queue

◆ each()

template<class T >
bool sptk::SynchronizedQueue< T >::each ( const CallbackFunction callbackFunction)
inline

Calls callbackFunction() for every list until false is returned

Current implementation does the job but isn't too efficient due to std::queue class limitations.

Parameters
callbackFunctionCallback function that is executed for list items
dataFunction-specific data
Returns
true if every list item was processed

◆ empty()

template<class T >
bool sptk::SynchronizedQueue< T >::empty ( ) const
inline

Returns true if the queue is empty

◆ pop()

template<class T >
bool sptk::SynchronizedQueue< T >::pop ( T &  item,
std::chrono::milliseconds  timeout 
)
inline

Pops a data item from the queue

If queue is empty then waits until timeoutMS milliseconds timeout occurs. Returns false if timeout occurs.

Parameters
itemT&, A queue item (output)
timeoutstd::chrono::milliseconds, Operation timeout in milliseconds

References sptk::Semaphore::sleep_for().

◆ push() [1/2]

template<class T >
void sptk::SynchronizedQueue< T >::push ( const T &  data)
inline

Pushes a data item to the queue

Automatically posts internal semaphore to indicate queue item availability.

Parameters
dataconst T&, A data item

References sptk::Semaphore::post().

◆ push() [2/2]

template<class T >
void sptk::SynchronizedQueue< T >::push ( T &&  data)
inline

Pushes a data item to the queue

Item is moved inside the queue. Automatically posts internal semaphore to indicate queue item availability.

Parameters
dataT&&, A data item

References sptk::Semaphore::post().

◆ size()

template<class T >
size_t sptk::SynchronizedQueue< T >::size ( ) const
inline

Returns number of items in the queue

◆ wakeup()

template<class T >
virtual void sptk::SynchronizedQueue< T >::wakeup ( )
inlinevirtual

Wakes up queue semaphore to interrupt waiting

Any waiting pop() operation immediately returns false.

References sptk::Semaphore::post().


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

Fri Oct 14 2022 09:58:45: SPTK 5.4.1