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

◆ size()

template<typename T , typename StoragePolicy , typename ConcurrencyPolicy = SingleThreadedPolicy, typename AccessPattern = QueueAccess>
size_t MayaFlux::Memory::RingBuffer< T, StoragePolicy, ConcurrencyPolicy, AccessPattern >::size ( ) const
inlinenoexcept

Get approximate element count.

Returns
Number of elements in buffer

For LockFreePolicy, value may be stale due to concurrent modification. Use for debugging/monitoring only, not for critical logic.

Definition at line 955 of file RingBuffer.hpp.

956 {
957 const size_t cap = m_storage.capacity();
958
959 if constexpr (is_lock_free) {
960 auto write = m_state.write_index.load(std::memory_order_acquire);
961 auto read = m_state.read_index.load(std::memory_order_acquire);
962 return (write >= read) ? (write - read) : (cap - read + write);
963 } else {
964 return (m_state.write_index >= m_state.read_index)
965 ? (m_state.write_index - m_state.read_index)
966 : (cap - m_state.read_index + m_state.write_index);
967 }
968 }
static constexpr bool is_lock_free

References MayaFlux::Memory::RingBuffer< T, StoragePolicy, ConcurrencyPolicy, AccessPattern >::is_lock_free, MayaFlux::Memory::RingBuffer< T, StoragePolicy, ConcurrencyPolicy, AccessPattern >::m_state, and MayaFlux::Memory::RingBuffer< T, StoragePolicy, ConcurrencyPolicy, AccessPattern >::m_storage.

Referenced by MayaFlux::Memory::RingBuffer< T, StoragePolicy, ConcurrencyPolicy, AccessPattern >::linearized_view(), MayaFlux::Memory::RingBuffer< T, StoragePolicy, ConcurrencyPolicy, AccessPattern >::linearized_view_mut(), and MayaFlux::Memory::RingBuffer< T, StoragePolicy, ConcurrencyPolicy, AccessPattern >::peek_oldest().

+ Here is the caller graph for this function: