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

◆ snapshot()

template<typename T , typename StoragePolicy , typename ConcurrencyPolicy = SingleThreadedPolicy, typename AccessPattern = QueueAccess>
std::vector< T > MayaFlux::Memory::RingBuffer< T, StoragePolicy, ConcurrencyPolicy, AccessPattern >::snapshot ( ) const
inline

Thread-safe snapshot of buffer contents.

Returns
Vector copy ordered by AccessPattern

Safe for lock-free contexts but allocates memory. For LockFreePolicy, provides consistent view despite concurrent access.

Not Real-time Safe: Allocates std::vector.

For MPSCPolicy, returns an empty vector. Use pop() to drain instead; a slot-by-slot index walk is not safe while producers are active.

// Lock-free queue
auto events = queue.snapshot(); // Safe despite concurrent push
for (const auto& event : events) {
write_to_disk(event); // Can block safely
}
std::vector< T > snapshot() const
Thread-safe snapshot of buffer contents.
Policy-driven unified circular buffer implementation.

Definition at line 1003 of file RingBuffer.hpp.

1004 {
1005 std::vector<T> result;
1006
1007 if constexpr (is_mpsc) {
1008 // snapshot() is not defined for MPSC - ready flags make a consistent
1009 // index-walk impossible without stopping producers. Use pop() to drain.
1010 return result;
1011 } else if constexpr (is_lock_free) {
1012 const size_t cap = m_storage.capacity();
1013 auto read = m_state.read_index.load(std::memory_order_acquire);
1014 auto write = m_state.write_index.load(std::memory_order_acquire);
1015
1016 result.reserve(cap);
1017 while (read != write) {
1018 result.push_back(m_storage.buffer[read]);
1019 read = State::increment(read, cap);
1020 }
1021 } else {
1022 auto view = linearized_view();
1023 result.assign(view.begin(), view.end());
1024 }
1025
1026 return result;
1027 }
std::span< T > linearized_view() const
Get linearized view of buffer contents.
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 >::linearized_view(), 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 >::resize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: