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

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

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

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

Public Member Functions

 PriorityBlockingQueue ()
 Creates a priority blocking queue that will only block a data requester when the queue is empty.
 
 PriorityBlockingQueue (size_t qSize)
 Creates a priority blocking queue that will block a data requester when the queue is empty or full. More...
 
 ~PriorityBlockingQueue ()
 Destructor.
 
size_t remainingCapacity ()
 Gets the remaining capacity of the priority queue based on the queueSize. More...
 
bool isEmpty ()
 Gets whether the priority queue is empty or not. More...
 
size_t size ()
 Gets the number of elements in the priority queue. More...
 
remove ()
 Removes an element from the priority queue. More...
 
void Enqueue (T const &value)
 Adds an element into the priority queue. More...
 
Dequeue ()
 Removes an element from the priority 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::priority_queue< T, std::vector< T >, IDataqueue
 The priority 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::PriorityBlockingQueue< T >

Creates a thread-safe priority 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.

Note
Use the directive USE_PRIORITY_QUEUE to enable the Connector to use priority blocking queues.

Constructor & Destructor Documentation

◆ PriorityBlockingQueue()

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

Creates a priority 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::PriorityBlockingQueue< T >::Dequeue ( )
inline

Removes an element from the priority 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::PriorityBlockingQueue< T >::Enqueue ( T const &  value)
inline

Adds an element into the priority 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::PriorityBlockingQueue< T >::isEmpty ( )
inline

Gets whether the priority queue is empty or not.

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

◆ poll()

template<class T >
T htgs::PriorityBlockingQueue< 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::PriorityBlockingQueue< T >::remainingCapacity ( )
inline

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

This function should only be used if the queueSize > 0

Returns
the remaining size of the priority queue before it is full

◆ remove()

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

Removes an element from the priority queue.

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

◆ size()

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

Gets the number of elements in the priority queue.

Returns
the number of elements in the priority queue

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