Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TBlockableAtomicQuasiQueue.ipp
Go to the documentation of this file.
2
3#include <Common/assertion.h>
4
5#include <utility>
6#include <stdexcept>
7
8namespace ph
9{
10
11template<typename T>
15
16template<typename T>
17inline TBlockableAtomicQuasiQueue<T>::TBlockableAtomicQuasiQueue(const std::size_t initialCapacity) :
18 m_queue(initialCapacity)
19{}
20
21template<typename T>
22template<typename U>
25 if(!m_queue.enqueue(std::forward<U>(item)))
26 {
27 throw std::runtime_error(
28 "Cannot enqueue an item to TBlockableAtomicQuasiQueue. Max subqueue size reached.");
29 }
30}
31
32template<typename T>
33template<std::input_iterator Iterator>
34inline void TBlockableAtomicQuasiQueue<T>::enqueueBulk(Iterator firstItem, const std::size_t numItems)
35{
36 if(!m_queue.enqueue_bulk(firstItem, numItems))
37 {
38 throw std::runtime_error(
39 "Cannot enqueue an item to TBlockableAtomicQuasiQueue. Max subqueue size reached.");
40 }
41}
42
43template<typename T>
44template<typename U>
46{
47 return m_queue.try_enqueue(std::forward<U>(item));
48}
49
50template<typename T>
51inline bool TBlockableAtomicQuasiQueue<T>::tryDequeue(T* const out_item)
52{
53 PH_ASSERT(out_item);
54 return m_queue.try_dequeue(*out_item);
55}
56
57template<typename T>
58inline void TBlockableAtomicQuasiQueue<T>::waitDequeue(T* const out_item)
59{
60 PH_ASSERT(out_item);
61 m_queue.wait_dequeue(*out_item);
63
64template<typename T>
65template<std::output_iterator<T> Iterator>
66inline std::size_t TBlockableAtomicQuasiQueue<T>::waitDequeueBulk(Iterator out_firstItem, std::size_t numItems)
67{
68 return m_queue.wait_dequeue_bulk(out_firstItem, numItems);
69}
70
71template<typename T>
73{
74 return m_queue.size_approx();
75}
76
77}// end namespace ph
bool tryEnqueue(U &&item)
Try to enqueue an item. Never allocate memory.
Definition TBlockableAtomicQuasiQueue.ipp:45
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 shoul...
Definition TBlockableAtomicQuasiQueue.ipp:34
void waitDequeue(T *out_item)
Blocks the current thread until there is something to dequeue.
Definition TBlockableAtomicQuasiQueue.ipp:58
TBlockableAtomicQuasiQueue()
Definition TBlockableAtomicQuasiQueue.ipp:12
void enqueue(U &&item)
Enqueue an item. Allocate memory if required. Basic aquire-release semantics are guaranteed....
Definition TBlockableAtomicQuasiQueue.ipp:23
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...
Definition TBlockableAtomicQuasiQueue.ipp:51
std::size_t estimatedSize() const
Approximated size of the queue.
Definition TBlockableAtomicQuasiQueue.ipp:72
std::size_t waitDequeueBulk(Iterator out_firstItem, std::size_t numItems)
Definition TBlockableAtomicQuasiQueue.ipp:66
The root for all renderer implementations.
Definition EEngineProject.h:6