MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::Memory::PendingQueue< T, Capacity > Class Template Reference

Bounded multi-producer, single-consumer queue of deferred operations. More...

#include <PendingQueue.hpp>

+ Inheritance diagram for MayaFlux::Memory::PendingQueue< T, Capacity >:
+ Collaboration diagram for MayaFlux::Memory::PendingQueue< T, Capacity >:

Classes

struct  Cell
 

Public Member Functions

template<typename Apply >
size_t drain (Apply &&apply)
 Apply and remove every published operation in claim order.
 
bool has_pending () const noexcept
 Cheap check for claimed operations awaiting a drain.
 
PendingQueue & operator= (const PendingQueue &)=delete
 
PendingQueue & operator= (PendingQueue &&)=delete
 
 PendingQueue () noexcept
 
 PendingQueue (const PendingQueue &)=delete
 
 PendingQueue (PendingQueue &&)=delete
 
bool push (T &&value) noexcept(std::is_nothrow_move_assignable_v< T >)
 Enqueue an operation from any thread.
 
 ~PendingQueue ()=default
 

Private Attributes

std::array< Cell, Capacity > m_cells
 
std::atomic< size_t > m_dequeue { 0 }
 
std::atomic< size_t > m_enqueue { 0 }
 

Static Private Attributes

static constexpr size_t MASK = Capacity - 1
 

Detailed Description

template<typename T, size_t Capacity>
class MayaFlux::Memory::PendingQueue< T, Capacity >

Bounded multi-producer, single-consumer queue of deferred operations.

Producers on any thread push an operation; the one owner of the guarded container drains the queue at a point where mutation is safe and applies each operation in the order it was claimed. Each cell carries its own sequence number, so a producer only claims a cell that is free and a consumer only reads a cell whose payload has been published. A full queue rejects the push without disturbing any other claim.

Capacity must be a power of two. T must be default constructible and move assignable; the drained cell is reset so the queue never retains a payload (for example a shared_ptr) past its application.

Only one thread may call drain() at a time.

if (!queue.push(Op { node, true })) {
// full: retry after the next drain
}
queue.drain([&](Op&& op) { apply(std::move(op)); });
bool push(T &&value) noexcept(std::is_nothrow_move_assignable_v< T >)
Enqueue an operation from any thread.
size_t drain(Apply &&apply)
Apply and remove every published operation in claim order.
Bounded multi-producer, single-consumer queue of deferred operations.

Definition at line 33 of file PendingQueue.hpp.


The documentation for this class was generated from the following file: