MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ drain()

template<typename T , size_t Capacity>
template<typename Apply >
size_t MayaFlux::Memory::PendingQueue< T, Capacity >::drain ( Apply &&  apply)
inline

Apply and remove every published operation in claim order.

Parameters
applyCallable taking T&&.
Returns
Number of operations applied.

Stops at the first cell whose producer has claimed but not yet published; that operation and everything behind it is applied by the next drain. Single consumer only.

Definition at line 93 of file PendingQueue.hpp.

94 {
95 size_t pos = m_dequeue.load(std::memory_order_relaxed);
96 size_t count = 0;
97
98 for (;;) {
99 Cell& cell = m_cells[pos & MASK];
100 if (cell.sequence.load(std::memory_order_acquire) != pos + 1) {
101 break;
102 }
103
104 T value = std::move(cell.value);
105 cell.value = T {};
106 cell.sequence.store(pos + Capacity, std::memory_order_release);
107 ++pos;
108 ++count;
109 m_dequeue.store(pos, std::memory_order_relaxed);
110
111 std::forward<Apply>(apply)(std::move(value));
112 }
113
114 return count;
115 }
glm::vec3 value
size_t count
std::atomic< size_t > m_dequeue
std::array< Cell, Capacity > m_cells
static constexpr size_t MASK

References count, MayaFlux::Memory::PendingQueue< T, Capacity >::m_cells, MayaFlux::Memory::PendingQueue< T, Capacity >::m_dequeue, MayaFlux::Memory::PendingQueue< T, Capacity >::MASK, MayaFlux::Memory::PendingQueue< T, Capacity >::Cell::sequence, value, and MayaFlux::Memory::PendingQueue< T, Capacity >::Cell::value.