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

◆ push()

template<typename T , size_t Capacity>
bool MayaFlux::Memory::PendingQueue< T, Capacity >::push ( T &&  value)
inlinenoexcept

Enqueue an operation from any thread.

Returns
false if the queue is full; the operation is left untouched.

Definition at line 57 of file PendingQueue.hpp.

58 {
59 size_t pos = m_enqueue.load(std::memory_order_relaxed);
60 Cell* cell = nullptr;
61
62 for (;;) {
63 cell = &m_cells[pos & MASK];
64 const size_t seq = cell->sequence.load(std::memory_order_acquire);
65 const auto diff = static_cast<std::intptr_t>(seq) - static_cast<std::intptr_t>(pos);
66
67 if (diff == 0) {
68 if (m_enqueue.compare_exchange_weak(pos, pos + 1, std::memory_order_relaxed)) {
69 break;
70 }
71 } else if (diff < 0) {
72 return false;
73 } else {
74 pos = m_enqueue.load(std::memory_order_relaxed);
75 }
76 }
77
78 cell->value = std::move(value);
79 cell->sequence.store(pos + 1, std::memory_order_release);
80 return true;
81 }
glm::vec3 value
std::atomic< size_t > m_enqueue
std::array< Cell, Capacity > m_cells
static constexpr size_t MASK

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