Blockable version of the TAtomicQuasiQueue
. For single-thread uses, it is a FIFO queue. For multi-thread uses, it is mostly a FIFO queue. Specifically, items put in by a given producer will all come out in the same order (FIFO). But there is no coordination between items from other producers–two items put in by two different producers will come out in an undefined order relative to each other (the interleaving between different streams of items from different producers is undefined, even with external synchronization). It is possible some items will starve in the queue if more items are enqueued than dequeued. Guarantees aquire-release semantics for items that are enqueued/dequeued.
More...
#include <TBlockableAtomicQuasiQueue.h>
|
| TBlockableAtomicQuasiQueue () |
|
| TBlockableAtomicQuasiQueue (std::size_t initialCapacity) |
|
template<typename U > |
void | enqueue (U &&item) |
| Enqueue an item. Allocate memory if required. Basic aquire-release semantics are guaranteed. This ensures that all the effects of work done by a thread before it enqueues an item will be visible on another thread after it dequeues that item. See tryDequeue(T*) for how to ensure the item can be dequeued on another thread.
|
|
template<std::input_iterator Iterator> |
void | enqueueBulk (Iterator firstItem, std::size_t numItems) |
| Enqueue multiple items at once. Similar to enqueue(1) . Use std::make_move_iterator if the items should be moved instead of copied.
|
|
template<typename U > |
bool | tryEnqueue (U &&item) |
| Try to enqueue an item. Never allocate memory.
|
|
bool | tryDequeue (T *out_item) |
| Try to dequeue an item. While there is no contention, dequeue fails if there is no item or the memory effect of enqueue is not visible. Dequeue can also fail spuriously if there is another consumer (under contention). To guarantee all enqueued items eventually got dequeued, memory effects must be made visible to the dequeuing threads.
|
|
void | waitDequeue (T *out_item) |
| Blocks the current thread until there is something to dequeue.
|
|
template<std::output_iterator< T > Iterator> |
std::size_t | waitDequeueBulk (Iterator out_firstItem, std::size_t numItems) |
|
std::size_t | estimatedSize () const |
| Approximated size of the queue.
|
|
template<typename T>
class ph::TBlockableAtomicQuasiQueue< T >
Blockable version of the TAtomicQuasiQueue
. For single-thread uses, it is a FIFO queue. For multi-thread uses, it is mostly a FIFO queue. Specifically, items put in by a given producer will all come out in the same order (FIFO). But there is no coordination between items from other producers–two items put in by two different producers will come out in an undefined order relative to each other (the interleaving between different streams of items from different producers is undefined, even with external synchronization). It is possible some items will starve in the queue if more items are enqueued than dequeued. Guarantees aquire-release semantics for items that are enqueued/dequeued.
◆ TBlockableAtomicQuasiQueue() [1/2]
◆ TBlockableAtomicQuasiQueue() [2/2]
◆ enqueue()
template<typename T >
template<typename U >
Enqueue an item. Allocate memory if required. Basic aquire-release semantics are guaranteed. This ensures that all the effects of work done by a thread before it enqueues an item will be visible on another thread after it dequeues that item. See tryDequeue(T*) for how to ensure the item can be dequeued on another thread.
- Note
- Thread-safe.
◆ enqueueBulk()
template<typename T >
template<std::input_iterator Iterator>
Enqueue multiple items at once. Similar to enqueue(1)
. Use std::make_move_iterator
if the items should be moved instead of copied.
◆ estimatedSize()
Approximated size of the queue.
- Returns
- Number of items in the queue. The esimation is only accurate if all memory writes to the queue is guaranteed to be visible. Note that 0 may be returned even if the queue is, in fact, not empty.
- Note
- Thread-safe.
◆ tryDequeue()
Try to dequeue an item. While there is no contention, dequeue fails if there is no item or the memory effect of enqueue is not visible. Dequeue can also fail spuriously if there is another consumer (under contention). To guarantee all enqueued items eventually got dequeued, memory effects must be made visible to the dequeuing threads.
- Returns
true
if an item is dequeued. false
otherwise (even if the queue is not empty).
- Note
- Thread-safe.
◆ tryEnqueue()
template<typename T >
template<typename U >
Try to enqueue an item. Never allocate memory.
- Returns
true
if the item is enqueued. false
otherwise.
- Note
- Thread-safe.
◆ waitDequeue()
Blocks the current thread until there is something to dequeue.
- Note
- Thread-safe.
◆ waitDequeueBulk()
template<typename T >
template<std::output_iterator< T > Iterator>
The documentation for this class was generated from the following files: