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

◆ try_push()

template<typename T , size_t Capacity>
bool MayaFlux::Journal::RingBuffer< T, Capacity >::try_push ( const T &  item)
inlinenoexcept

Attempt to write an element (wait-free)

Returns
true if write succeeded, false if buffer full

Definition at line 30 of file RingBuffer.hpp.

31 {
32 const auto current_write = m_write_index.load(std::memory_order_relaxed);
33 const auto next_write = increment(current_write);
34
35 if (next_write == m_read_index.load(std::memory_order_acquire)) {
36 return false;
37 }
38
39 m_buffer[current_write] = item;
40
41 m_write_index.store(next_write, std::memory_order_release);
42
43 return true;
44 }
std::array< T, Capacity > m_buffer
static constexpr size_t increment(size_t index) noexcept
std::atomic< size_t > m_read_index
std::atomic< size_t > m_write_index

References MayaFlux::Journal::RingBuffer< T, Capacity >::increment(), MayaFlux::Journal::RingBuffer< T, Capacity >::m_buffer, MayaFlux::Journal::RingBuffer< T, Capacity >::m_read_index, and MayaFlux::Journal::RingBuffer< T, Capacity >::m_write_index.

+ Here is the call graph for this function: