Thread safe queue for c++.
More...
#include <TSQueue.hpp>
|
using | MutexType = std::mutex |
|
using | ReadLock = std::unique_lock< MutexType > |
|
using | WriteLock = std::unique_lock< MutexType > |
|
template<class T>
class TSQueue< T >
Thread safe queue for c++.
supports move c'tor and copy c'tor in a thread-safe manner
- Author
- Sean Grimes, spg63.nosp@m.@cs..nosp@m.drexe.nosp@m.l.ed.nosp@m.u
- Date
- 12-27-15
◆ backing_queue()
template<class T>
std::queue<T> TSQueue< T >::backing_queue |
( |
| ) |
|
|
inline |
Get copy of underlying std::queue.
- Returns
- The underlying queue used in this class
◆ empty()
Check is queue is empty.
- Returns
- True if empty, false otherwise
◆ push()
template<class T>
void TSQueue< T >::push |
( |
const T & |
element | ) |
|
|
inline |
Single writer thread access
- Parameters
-
element | Item to be pushed onto the queue |
◆ size()
Get number of items in queue.
- Returns
- Number of items in the queue
◆ try_and_pop() [1/2]
template<class T>
bool TSQueue< T >::try_and_pop |
( |
T & |
item | ) |
|
|
inline |
Will not wait if queue is empty.
Will call queue.front(), if no item is available will immediately return. If item is available it will std::move it to the item passed by reference
- Parameters
-
item | Will be populated with item at front of the queue if available, otherwise untouched |
- Returns
- True if item is available, false if no item available
◆ try_and_pop() [2/2]
template<class T>
bool TSQueue< T >::try_and_pop |
( |
T & |
item, |
|
|
std::chrono::milliseconds |
timeout |
|
) |
| |
|
inline |
Waits for 'timeout' if queue is empty.
More cpu efficient alternative to while(true) try_and_pop. Will wait for 'timeout' amount of time while the queue is empty before returning.
- Parameters
-
item | Will be populated with item at front of the queue if available, otherwise untouched |
timeout | Amount of time to wait on empty queue before returning (std::chrono::milliseconds) |
- Returns
- True if item is available, false if no item available
◆ wait_and_pop()
Waits while queue is empty.
Thread will wait indefinitely while queue is empty, use with caution
- Returns
- Element at the front of the queue
The documentation for this class was generated from the following file: