|
typedef T | value_type |
| A type that represents the data type stored in a concurrent queue.
|
|
typedef Alloc | allocator_type |
| A type that represents the allocator class for the concurrent queue.
|
|
typedef value_type & | reference |
| A type that provides a reference to an element stored in a concurrent queue.
|
|
typedef std::condition_variable_any | condition_type |
| A type that provides a waitable condition of the concurrent queue.
|
|
typedef std::allocator_traits< allocator_type >::pointer | pointer |
| A type that provides a pointer to an element stored in a concurrent queue.
|
|
typedef std::allocator_traits< allocator_type >::const_pointer | const_pointer |
| A type that provides a const pointer to an element stored in a concurrent queue.
|
|
typedef Queue< T, Alloc > | queue_type |
| A type that represents the underlying non-thread-safe data structure for the concurrent queue.
|
|
typedef queue_type::iterator | iterator |
| A type that represents a non-thread-safe iterator over the elements in a concurrent queue.
|
|
typedef queue_type::const_iterator | const_iterator |
| A type that represents a non-thread-safe const iterator over elements in a concurrent queue.
|
|
typedef std::reverse_iterator< iterator > | reverse_iterator |
| A type that represents a reverse non-thread-safe iterator over the elements in a concurrent queue.
|
|
typedef std::reverse_iterator< const_iterator > | const_reverse_iterator |
| A type that represents a reverse non-thread-safe const iterator over elements in a concurrent queue.
|
|
typedef std::shared_timed_mutex | mutex_type |
| A type that represents the mutex protecting the concurrent queue.
|
|
typedef std::shared_lock< mutex_type > | read_lock_type |
| A type representing a lock on the concurrent queue's mutex which is sufficient to read data in a thread-safe manner.
|
|
typedef std::unique_lock< mutex_type > | write_lock_type |
| A type representing a lock on the concurrent queue's mutex which is sufficient to write data in a thread-safe manner.
|
|
typedef std::iterator_traits< iterator >::difference_type | difference_type |
| A type that provides the signed distance between two elements in a concurrent queue.
|
|
typedef size_t | size_type |
| A type that counts the number of elements in a concurrent queue.
|
|
|
|
| concurrent_queue ()=default |
| Default Constructor. More...
|
|
| concurrent_queue (const allocator_type &alloc) |
| Default Constructor. More...
|
|
| concurrent_queue (size_type n, const allocator_type &alloc=allocator_type()) |
| Fill Constructor. More...
|
|
| concurrent_queue (size_type n, const value_type &val, const allocator_type &alloc=allocator_type()) |
| Fill Constructor. More...
|
|
template<typename InputIterator > |
| concurrent_queue (InputIterator first, InputIterator last, const allocator_type &alloc=allocator_type()) |
| Range Constructor. More...
|
|
| concurrent_queue (const concurrent_queue &other) |
| Copy Constructor. More...
|
|
| concurrent_queue (const concurrent_queue &other, const allocator_type &alloc) |
| Copy Constructor with allocator. More...
|
|
| concurrent_queue (concurrent_queue &&other) noexcept |
| Move Constructor. More...
|
|
| concurrent_queue (concurrent_queue &&other, const allocator_type &alloc) noexcept |
| Move Constructor. More...
|
|
| concurrent_queue (std::initializer_list< T > init, const allocator_type &alloc=allocator_type()) |
| Initializer List Constructor. More...
|
|
|
| ~concurrent_queue ()=default |
| Destructor. More...
|
|
|
concurrent_queue & | operator= (const concurrent_queue &other) |
| Copy Assignment Operator. More...
|
|
concurrent_queue & | operator= (concurrent_queue &&other) noexcept |
| Move Assignment Operator. More...
|
|
|
These methods are safe for use in situations where the queue will be concurrently accessed by multiple threads.
|
void | clear () noexcept |
| Clears the concurrent queue, destroying any currently enqueued elements. More...
|
|
template<class... Args> |
void | emplace (Args &&... args) |
| Constructs a new element in place at the end of the concurrent queue. More...
|
|
bool | empty () const noexcept |
| Tests if the concurrent queue is empty at the moment this method is called. More...
|
|
allocator_type | get_allocator () const noexcept |
| Returns a copy of the allocator used to construct the concurrent queue. More...
|
|
void | push (const T &value) |
| Enqueues an item at tail end of the concurrent queue. More...
|
|
void | push (T &&value) |
| Enqueues an item at tail end of the concurrent queue. More...
|
|
size_t | size () const |
| Returns the number of items in the queue. More...
|
|
bool | try_pop (T &destination) |
| Dequeues an item from the queue if one is available. More...
|
|
template<class Rep , class Period > |
bool | try_pop_for (T &destination, const std::chrono::duration< Rep, Period > &timeout_duration) |
| Dequeues an item from the queue if one is available within the specified timeout. More...
|
|
|
These methods are not recommended for use in production code and will generate warnings when used. That said, they're helpful for testing and debug, which is why they are included.
|
iterator | begin () |
| Returns an iterator of type iterator to the beginning of the concurrent queue. More...
|
|
const_iterator | begin () const |
| Returns an iterator of type const_iterator to the beginning of the concurrent queue. More...
|
|
const_iterator | cbegin () const |
| Returns an iterator of type const_iterator to the beginning of the concurrent queue. More...
|
|
iterator | end () |
| Returns an iterator of type iterator to the end of the concurrent queue. More...
|
|
const_iterator | end () const |
| Returns an iterator of type const_iterator to the end of the concurrent queue. More...
|
|
const_iterator | cend () const |
| Returns an iterator of type const_iterator to the end of the concurrent queue. More...
|
|
|
These methods provide the ability to lock the concurrent_queue for thread-safe iteration. They are primarily intended for test and debug use, and care must be taken when explicitely locking the queue to avoid deadlock. These methods are NOT recommended for production code, and will produce warnings when used.
|
read_lock_type | acquire_read_lock () const |
| Lock the queue in a manner in which it is safe for multiple threads to read-iterate over it. More...
|
|
write_lock_type | acquire_write_lock () |
| Lock the queue in a manner in which it is safe for multiple threads to write-iterate over it. More...
|
|
|
|
template<class Ty , template< class, class > class Q, class A > |
bool | operator== (const concurrent_queue< Ty, Q, A > &lhs, const concurrent_queue< Ty, Q, A > &rhs) |
| Equality Operator. More...
|
|
template<class Ty , template< class, class > class Q, class A > |
bool | operator!= (const concurrent_queue< Ty, Q, A > &lhs, const concurrent_queue< Ty, Q, A > &rhs) |
| Inequality Operator. More...
|
|
|
template<class Ty , template< class, class > class Q, class A > |
void | std::swap (concurrent_queue< Ty, Q, A > &lhs, concurrent_queue< Ty, Q, A > &rhs) |
| Swap Operator. More...
|
|
template<class T, template< class, class > class Queue = std::deque, class Alloc = std::allocator<T>>
class concurrent_queue< T, Queue, Alloc >
The concurrent_queue
class is a sequence container class that allows first-in, first-out access to its elements.
It enables a limited set of concurrency-safe operations, such as push and try_pop. Here, concurrency-safe means pointers or iterators are always valid. It's not a guarantee of element initialization, or of a particular traversal order.
- Template Parameters
-
T | The data type of the elements to be stored in the queue. |
Queue | Underlying concurrent queue data structure. Defaults to std::deque . |
AllocThe | type that represents the stored allocator object that encapsulates details about the allocation and deallocation of memory for this concurrent queue. This argument is optional and the default value is allocator<T>. |
template<class T , template< class, class > class Queue = std::deque, class Alloc = std::allocator<T>>
template<typename InputIterator >
Range Constructor.
Constructs a container with as many elements as the range [first,last), with each element emplace-constructed from its corresponding element in that range, in the same order.
- Template Parameters
-
InputIterator | Input Iterator to value_type |
- Parameters
-
[in] | first | Iterator to the first element of the range |
[in] | last | Iterator to the one-past-last element of the range |
template<class T , template< class, class > class Queue = std::deque, class Alloc = std::allocator<T>>
Returns an iterator of type iterator to the beginning of the concurrent queue.
This method is not concurrency-safe. The iterators for the concurrent_queue class are primarily intended for debugging, as they are slow, and iteration is not concurrency-safe with respect to other queue operations.
- Returns
- An iterator of type iterator to the beginning of the concurrent queue.
template<class T , template< class, class > class Queue = std::deque, class Alloc = std::allocator<T>>
Returns an iterator of type const_iterator to the beginning of the concurrent queue.
This method is not concurrency-safe. The iterators for the concurrent_queue class are primarily intended for debugging, as they are slow, and iteration is not concurrency-safe with respect to other queue operations.
- Returns
- An iterator of type const_iterator to the beginning of the concurrent queue.
template<class T , template< class, class > class Queue = std::deque, class Alloc = std::allocator<T>>
Returns an iterator of type const_iterator to the beginning of the concurrent queue.
This method is not concurrency-safe. The iterators for the concurrent_queue class are primarily intended for debugging, as they are slow, and iteration is not concurrency-safe with respect to other queue operations.
- Returns
- An iterator of type const_iterator to the beginning of the concurrent queue.
template<class T , template< class, class > class Queue = std::deque, class Alloc = std::allocator<T>>
Returns an iterator of type const_iterator to the end of the concurrent queue.
This method is not concurrency-safe. The iterators for the concurrent_queue class are primarily intended for debugging, as they are slow, and iteration is not concurrency-safe with respect to other queue operations.
- Returns
- An iterator of type const_iterator to the end of the concurrent queue.
template<class T , template< class, class > class Queue = std::deque, class Alloc = std::allocator<T>>
template<class... Args>
Constructs a new element in place at the end of the concurrent queue.
This method is concurrency-safe. This method is concurrency-safe with respect to calls to the methods push
, emplace
, pop
, and empty
.
- Template Parameters
-
Args | Types of args, generally deduced automatically. |
- Parameters
-
[in] | args | Arguments to forward to the constructor of the element. |
template<class T , template< class, class > class Queue = std::deque, class Alloc = std::allocator<T>>
Tests if the concurrent queue is empty at the moment this method is called.
This method is concurrency-safe. While this method is concurrency-safe with respect to calls to the methods push
, emplace
, pop
, and empty
, the value returned might be incorrect by the time it is inspected by the calling thread.
- Returns
- true if the concurrent queue was empty at the moment we looked, false otherwise.
template<class T , template< class, class > class Queue = std::deque, class Alloc = std::allocator<T>>
Returns an iterator of type iterator to the end of the concurrent queue.
This method is not concurrency-safe. The iterators for the concurrent_queue class are primarily intended for debugging, as they are slow, and iteration is not concurrency-safe with respect to other queue operations.
- Returns
- An iterator of type iterator to the end of the concurrent queue.
template<class T , template< class, class > class Queue = std::deque, class Alloc = std::allocator<T>>
Returns an iterator of type const_iterator to the end of the concurrent queue.
This method is not concurrency-safe. The iterators for the concurrent_queue class are primarily intended for debugging, as they are slow, and iteration is not concurrency-safe with respect to other queue operations.
- Returns
- An iterator of type const_iterator to the end of the concurrent queue.
template<class T , template< class, class > class Queue = std::deque, class Alloc = std::allocator<T>>
Enqueues an item at tail end of the concurrent queue.
This method is concurrency-safe. push
is concurrency-safe with respect to calls to the methods push
emplace
, pop
, and empty
.
- Parameters
-
[in] | value | The item to be added to the queue. |
template<class T , template< class, class > class Queue = std::deque, class Alloc = std::allocator<T>>
Enqueues an item at tail end of the concurrent queue.
This method is concurrency-safe. push
is concurrency-safe with respect to calls to the methods push
emplace
, pop
, and empty
.
- Parameters
-
[in] | value | The item to be added to the queue. |
template<class T , template< class, class > class Queue = std::deque, class Alloc = std::allocator<T>>
Dequeues an item from the queue if one is available.
This method is concurrency-safe. If an item was successfully dequeued, the parameter destination
receives the dequeued value, the original value held in the queue is destroyed, and this function returns true. If there was no item to dequeue, this function returns false without blocking, and the contents of the destination
parameter are undefined. A false return value does not necessarily mean the queue is empty. try_pop
is concurrency-safe with respect to calls to the methods emplace
, push
, try_pop
, and empty
.
- Parameters
-
[out] | destination | A reference to a location to store the dequeued item. |
- Returns
- true if an item was successfully dequeued, false otherwise.
template<class T , template< class, class > class Queue = std::deque, class Alloc = std::allocator<T>>
template<class Rep , class Period >
bool concurrent_queue< T, Queue, Alloc >::try_pop_for |
( |
T & |
destination, |
|
|
const std::chrono::duration< Rep, Period > & |
timeout_duration |
|
) |
| |
|
inline |
Dequeues an item from the queue if one is available within the specified timeout.
This method is concurrency-safe. If an item was successfully dequeued, the parameter destination
receives the dequeued value, the original value held in the queue is destroyed, and this function returns true. If there was no item to dequeue, this function returns false without blocking, and the contents of the destination
parameter are undefined. A false return value does not necessarily mean the queue is empty. try_pop
is concurrency-safe with respect to calls to the methods emplace
, push
, try_pop
, and empty
.
- Parameters
-
[out] | destination | A reference to a location to store the dequeued item. |
[in] | timeout_duration | The maximum length of time try_pop_for will attempt to pop the queue before declaring failure. |
- Returns
- true if an item was successfully dequeued, false otherwise.