CIRCT
20.0.0git
|
Thread safe queue. More...
#include <Utils.h>
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... | |
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.
|
private |
|
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.
|
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.
|
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 onto the queue.
Definition at line 55 of file Utils.h.
References esi::utils::TSQueue< T >::q, and esi::utils::TSQueue< T >::qM.
|
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().
|
private |
Definition at line 44 of file Utils.h.
Referenced by esi::utils::TSQueue< T >::empty(), esi::utils::TSQueue< T >::pop(), and esi::utils::TSQueue< T >::push().
|
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().