libosmscout  0.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules
osmscout::ProcessingQueue< T > Class Template Reference

A ProcessingQueue is a special multi-threaded safe implementation of a queue. More...

#include <ProcessingQueue.h>

Public Member Functions

bool Finished ()
 Return true, if the queue is stopped and empty, else false. More...
 
ProcessingQueueoperator= (const ProcessingQueue &)=delete
 
std::optional< T > PopTask ()
 Move one data entry out of the queue (FIFO semantics). More...
 
 ProcessingQueue ()
 Initialize a unbounded queue. More...
 
 ProcessingQueue (const ProcessingQueue &)=delete
 
 ProcessingQueue (size_t queueLimit)
 Initialize a bounded queue. More...
 
void PushTask (const T &task)
 Push a copy of the given data into the queue. More...
 
void PushTask (T &&task)
 Push a copy or move the given data into the queue. More...
 
void Stop ()
 Signal that all data has been pushed into the queue. More...
 
virtual ~ProcessingQueue ()=default
 

Detailed Description

template<typename T>
class osmscout::ProcessingQueue< T >

A ProcessingQueue is a special multi-threaded safe implementation of a queue.

The goal is to use this queues as a asynchronous pipeline between individual agents or worker threads.

The queue has FIFO semantics.

A queue can have multiple producers and consumers. There is currently no Peek() method data that has been taken has either to be consumed, pushed back or dropped.

The queue data should be movable but can be copyable also. If the content is not movable additional CPU overhead for copying data is to be expected.

Note that even is the content is moveable is should be assumed that moving data through the queue has it own cost.

Template Parameters
TType of the queue content

Constructor & Destructor Documentation

◆ ProcessingQueue() [1/3]

template<class T >
osmscout::ProcessingQueue< T >::ProcessingQueue ( )
default

Initialize a unbounded queue.

Template Parameters
T

◆ ProcessingQueue() [2/3]

template<class T >
osmscout::ProcessingQueue< T >::ProcessingQueue ( size_t  queueLimit)
explicit

Initialize a bounded queue.

The queue is guaranteed to hold no more than the given amount of data entries. Producer will be blocked until the queue shrinks below its limit before data can be pushed.

Template Parameters
T
Parameters
queueLimitQueue size limit

◆ ProcessingQueue() [3/3]

template<typename T >
osmscout::ProcessingQueue< T >::ProcessingQueue ( const ProcessingQueue< T > &  )
delete

◆ ~ProcessingQueue()

template<typename T >
virtual osmscout::ProcessingQueue< T >::~ProcessingQueue ( )
virtualdefault

Member Function Documentation

◆ Finished()

template<class R >
bool osmscout::ProcessingQueue< R >::Finished

Return true, if the queue is stopped and empty, else false.

Template Parameters
R
Returns
true, if stopped and empty, else false

Referenced by osmscout::AsyncWorker::Loop().

◆ operator=()

template<typename T >
ProcessingQueue& osmscout::ProcessingQueue< T >::operator= ( const ProcessingQueue< T > &  )
delete

◆ PopTask()

template<class T >
std::optional< T > osmscout::ProcessingQueue< T >::PopTask

Move one data entry out of the queue (FIFO semantics).

No data will be returned if the queue is stopped and empty.

Template Parameters
T
Returns

Referenced by osmscout::AsyncWorker::Loop().

◆ PushTask() [1/2]

template<class T >
void osmscout::ProcessingQueue< T >::PushTask ( const T &  task)

Push a copy of the given data into the queue.

Pushing data will be blocked until queue size is below limit.

Template Parameters
T
Parameters
task

◆ PushTask() [2/2]

template<class T >
void osmscout::ProcessingQueue< T >::PushTask ( T &&  task)

Push a copy or move the given data into the queue.

Pushing data will be blocked until queue size is below limit.

Template Parameters
T
Parameters
task

◆ Stop()

template<class R >
void osmscout::ProcessingQueue< R >::Stop

Signal that all data has been pushed into the queue.

Template Parameters
R

Referenced by osmscout::AsyncWorker::DeleteLater(), and osmscout::AsyncWorker::~AsyncWorker().


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