Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
ph::TAtomicQuasiQueue< T > Class Template Referencefinal

A multi-producer, multi-consumer, lock-free concurrent queue-like structure. 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 <TAtomicQuasiQueue.h>

Public Member Functions

 TAtomicQuasiQueue ()
 
 TAtomicQuasiQueue (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.
 
template<std::output_iterator< T > Iterator>
std::size_t tryDequeueBulk (Iterator out_firstItem, std::size_t numItems)
 
std::size_t estimatedSize () const
 Approximated size of the queue.
 

Detailed Description

template<typename T>
class ph::TAtomicQuasiQueue< T >

A multi-producer, multi-consumer, lock-free concurrent queue-like structure. 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.

Constructor & Destructor Documentation

◆ TAtomicQuasiQueue() [1/2]

template<typename T >
ph::TAtomicQuasiQueue< T >::TAtomicQuasiQueue ( )
inline

◆ TAtomicQuasiQueue() [2/2]

template<typename T >
ph::TAtomicQuasiQueue< T >::TAtomicQuasiQueue ( std::size_t initialCapacity)
inlineexplicit

Member Function Documentation

◆ enqueue()

template<typename T >
template<typename U >
void ph::TAtomicQuasiQueue< T >::enqueue ( U && item)
inline

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>
void ph::TAtomicQuasiQueue< T >::enqueueBulk ( Iterator firstItem,
std::size_t numItems )
inline

Enqueue multiple items at once. Similar to enqueue(1). Use std::make_move_iterator if the items should be moved instead of copied.

◆ estimatedSize()

template<typename T >
std::size_t ph::TAtomicQuasiQueue< T >::estimatedSize ( ) const
inline

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()

template<typename T >
bool ph::TAtomicQuasiQueue< T >::tryDequeue ( T * out_item)
inline

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.

◆ tryDequeueBulk()

template<typename T >
template<std::output_iterator< T > Iterator>
std::size_t ph::TAtomicQuasiQueue< T >::tryDequeueBulk ( Iterator out_firstItem,
std::size_t numItems )
inline

◆ tryEnqueue()

template<typename T >
template<typename U >
bool ph::TAtomicQuasiQueue< T >::tryEnqueue ( U && item)
inline

Try to enqueue an item. Never allocate memory.

Returns
true if the item is enqueued. false otherwise.
Note
Thread-safe.

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