MayaFlux 0.5.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 1053 of file RingBuffer.hpp.

1054 {
1055 const size_t cap = m_storage.capacity();
1056
1057 if constexpr (is_mpsc) {
1058 auto claim = m_state.claim_index.load(std::memory_order_acquire);
1059 auto read = m_state.read_index.load(std::memory_order_acquire);
1060 return (claim - read) & (cap - 1);
1061 } else if constexpr (is_lock_free) {
1062 auto write = m_state.write_index.load(std::memory_order_acquire);
1063 auto read = m_state.read_index.load(std::memory_order_acquire);
1064 return (write >= read) ? (write - read) : (cap - read + write);
1065 } else {
1066 return (m_state.write_index >= m_state.read_index)
1067 ? (m_state.write_index - m_state.read_index)
1068 : (cap - m_state.read_index + m_state.write_index);
1069 }
1070 }
static constexpr bool is_lock_free
static constexpr bool is_mpsc

References MayaFlux::Memory::RingBuffer< T, StoragePolicy, ConcurrencyPolicy, AccessPattern >::is_lock_free, MayaFlux::Memory::RingBuffer< T, StoragePolicy, ConcurrencyPolicy, AccessPattern >::is_mpsc, 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: