HTGS  v2.0
The Hybrid Task Graph Scheduler
htgs::BlockingQueue< T > Class Template Reference

Creates a thread-safe queue that will wait when no data is available and can block if the queue is full. More...

#include <htgs/core/queue/BlockingQueue.hpp>

Collaboration diagram for htgs::BlockingQueue< T >:
Collaboration graph

Public Member Functions

 BlockingQueue ()
 Creates a blocking queue that will only block a data requester when the queue is empty.
 
 BlockingQueue (size_t qSize)
 Creates a blocking queue that will block a data requester when the queue is empty or full. More...
 
 ~BlockingQueue ()
 Destructor.
 
size_t remainingCapacity ()
 Gets the remaining capacity of the queue based on the queueSize. More...
 
bool isEmpty ()
 Gets whether the queue is empty or not. More...
 
size_t size ()
 Gets the number of elements in the queue. More...
 
remove ()
 Removes an element from the queue. More...
 
void Enqueue (T const &value)
 Adds an element into the queue. More...
 
Dequeue ()
 Removes an element from the queue. More...
 
poll (size_t timeout)
 Polls for data given the specified timeout time in microseconds. More...
 

Private Attributes

size_t queueSize
 The maximum size of the queue, set to -1 for infinite size.
 
std::queue< T > queue
 The FIFO queue.
 
std::mutex mutex
 The mutex to ensure thread safety.
 
std::condition_variable condition
 The condition variable used for waking up waiting threads.
 

Detailed Description

template<class T>
class htgs::BlockingQueue< T >

Creates a thread-safe queue that will wait when no data is available and can block if the queue is full.

If the size of the queue is specified to be less than 0 (default constructor), then the queue will not block if the queue is full.

Constructor & Destructor Documentation

◆ BlockingQueue()

template<class T>
htgs::BlockingQueue< T >::BlockingQueue ( size_t  qSize)
inline

Creates a blocking queue that will block a data requester when the queue is empty or full.

Parameters
qSize

Member Function Documentation

◆ Dequeue()

template<class T>
T htgs::BlockingQueue< T >::Dequeue ( )
inline

Removes an element from the queue.

Returns
the next element in the queue
Note
Is thread safe.
Will block if the queue is empty.

◆ Enqueue()

template<class T>
void htgs::BlockingQueue< T >::Enqueue ( T const &  value)
inline

Adds an element into the queue.

Parameters
valuethe element to be added
Note
Is thread safe.
Will block if the maximum queue size > 0 and the number of elements in the queue is equal to the maximum queue size

◆ isEmpty()

template<class T>
bool htgs::BlockingQueue< T >::isEmpty ( )
inline

Gets whether the queue is empty or not.

Returns
whether the queue is empty
Return values
TRUEif the queue is empty
FALSEif the queue is not empty

◆ poll()

template<class T>
T htgs::BlockingQueue< T >::poll ( size_t  timeout)
inline

Polls for data given the specified timeout time in microseconds.

Parameters
timeoutthe timeout time in microseconds
Returns
the data or nullptr if the timeout expires
Return values
dataif data exists prior to the timeout time
nullptrif no data exists after the timeout time expires

◆ remainingCapacity()

template<class T>
size_t htgs::BlockingQueue< T >::remainingCapacity ( )
inline

Gets the remaining capacity of the queue based on the queueSize.

This function should only be used if the queueSize > 0

Returns
the remaining size of the queue before it is full

◆ remove()

template<class T>
T htgs::BlockingQueue< T >::remove ( )
inline

Removes an element from the queue.

Returns
an element from the queue
Note
This function is not thread safe.

◆ size()

template<class T>
size_t htgs::BlockingQueue< T >::size ( )
inline

Gets the number of elements in the queue.

Returns
the number of elements in the queue

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