Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TAtomicQuasiQueue.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>
13 m_queue()
14{}
15
16template<typename T>
17inline TAtomicQuasiQueue<T>::TAtomicQuasiQueue(const std::size_t initialCapacity) :
18 m_queue(initialCapacity)
19{}
20
21template<typename T>
22template<typename U>
23inline void TAtomicQuasiQueue<T>::enqueue(U&& item)
24{
25 if(!m_queue.enqueue(std::forward<U>(item)))
26 {
27 throw std::runtime_error(
28 "Cannot enqueue an item to TAtomicQuasiQueue. Max subqueue size reached.");
29 }
30}
31
32template<typename T>
33template<std::input_iterator Iterator>
34inline void TAtomicQuasiQueue<T>::enqueueBulk(Iterator firstItem, 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 TAtomicQuasiQueue. Max subqueue size reached.");
40 }
41}
43template<typename T>
44template<typename U>
46{
47 return m_queue.try_enqueue(std::forward<U>(item));
48}
50template<typename T>
51inline bool TAtomicQuasiQueue<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>
58template<std::output_iterator<T> Iterator>
59inline std::size_t TAtomicQuasiQueue<T>::tryDequeueBulk(Iterator out_firstItem, std::size_t numItems)
60{
61 return m_queue.try_dequeue_bulk(out_firstItem, numItems);
63
64template<typename T>
65inline std::size_t TAtomicQuasiQueue<T>::estimatedSize() const
66{
67 return m_queue.size_approx();
68}
70}// end namespace ph
std::size_t estimatedSize() const
Approximated size of the queue.
Definition TAtomicQuasiQueue.ipp:65
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 TAtomicQuasiQueue.ipp:51
std::size_t tryDequeueBulk(Iterator out_firstItem, std::size_t numItems)
Definition TAtomicQuasiQueue.ipp:59
TAtomicQuasiQueue()
Definition TAtomicQuasiQueue.ipp:12
bool tryEnqueue(U &&item)
Try to enqueue an item. Never allocate memory.
Definition TAtomicQuasiQueue.ipp:45
void enqueue(U &&item)
Enqueue an item. Allocate memory if required. Basic aquire-release semantics are guaranteed....
Definition TAtomicQuasiQueue.ipp:23
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 TAtomicQuasiQueue.ipp:34
The root for all renderer implementations.
Definition EEngineProject.h:6