CIRCT  20.0.0git
Public Member Functions | Private Types | Private Attributes | List of all members
esi::utils::TSQueue< T > Class Template Reference

Thread safe queue. More...

#include <Utils.h>

Collaboration diagram for esi::utils::TSQueue< T >:
Collaboration graph
[legend]

Public Member Functions

template<typename... E>
void push (E... t)
 Push onto the queue. More...
 
std::optional< T > pop ()
 Pop something off the queue but return nullopt if the queue is empty. More...
 
void pop (std::function< bool(const T &)> callback)
 Call the callback for the front of the queue (if anything is there). More...
 
bool empty () const
 Is the queue empty? More...
 

Private Types

using Lock = std::lock_guard< std::mutex >
 

Private Attributes

std::mutex qM
 The queue and its mutex. More...
 
std::queue< T > q
 
std::mutex popM
 A mutex to ensure that only one 'pop' operation is happening at a time. More...
 

Detailed Description

template<typename T>
class esi::utils::TSQueue< T >

Thread safe queue.

Just wraps std::queue protected with a lock. Long term, we need to avoid copying data. It has a lot of data copies currently.

Definition at line 39 of file Utils.h.

Member Typedef Documentation

◆ Lock

template<typename T >
using esi::utils::TSQueue< T >::Lock = std::lock_guard<std::mutex>
private

Definition at line 40 of file Utils.h.

Member Function Documentation

◆ empty()

template<typename T >
bool esi::utils::TSQueue< T >::empty ( ) const
inline

Is the queue empty?

Definition at line 94 of file Utils.h.

References esi::utils::TSQueue< T >::q, and esi::utils::TSQueue< T >::qM.

◆ pop() [1/2]

template<typename T >
std::optional<T> esi::utils::TSQueue< T >::pop ( )
inline

Pop something off the queue but return nullopt if the queue is empty.

Why doesn't std::queue have anything like this?

Definition at line 62 of file Utils.h.

References esi::utils::TSQueue< T >::popM, esi::utils::TSQueue< T >::q, and esi::utils::TSQueue< T >::qM.

◆ pop() [2/2]

template<typename T >
void esi::utils::TSQueue< T >::pop ( std::function< bool(const T &)>  callback)
inline

Call the callback for the front of the queue (if anything is there).

Only pop it off the queue if the callback returns true.

Definition at line 74 of file Utils.h.

References esi::utils::TSQueue< T >::popM, esi::utils::TSQueue< T >::q, and esi::utils::TSQueue< T >::qM.

◆ push()

template<typename T >
template<typename... E>
void esi::utils::TSQueue< T >::push ( E...  t)
inline

Push onto the queue.

Definition at line 55 of file Utils.h.

References esi::utils::TSQueue< T >::q, and esi::utils::TSQueue< T >::qM.

Member Data Documentation

◆ popM

template<typename T >
std::mutex esi::utils::TSQueue< T >::popM
private

A mutex to ensure that only one 'pop' operation is happening at a time.

It is critical that locks be obtained on this and qM same order in both pop methods. This lock should be obtained first since one of the pop methods must unlock qM then relock it.

Definition at line 50 of file Utils.h.

Referenced by esi::utils::TSQueue< T >::pop().

◆ q

template<typename T >
std::queue<T> esi::utils::TSQueue< T >::q
private

◆ qM

template<typename T >
std::mutex esi::utils::TSQueue< T >::qM
mutableprivate

The queue and its mutex.

Definition at line 43 of file Utils.h.

Referenced by esi::utils::TSQueue< T >::empty(), esi::utils::TSQueue< T >::pop(), and esi::utils::TSQueue< T >::push().


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