Skip to main content
Pigweed's logo Pigweed
code_xml
  1. Home
  2. Reference
  3. C/C++
  4. Data structures & utilities
  5. pw_containers
  6. Queues
  7. pw::FixedLockFreeSpscQueue< T, kInlineCapacity, SizeType > Class Template Reference
pw::FixedLockFreeSpscQueue< T, kInlineCapacity, SizeType > Class Template Reference

Overview

template<typename T, size_t kInlineCapacity = containers::kExternalStorage, typename SizeType = typename LockFreeSpscQueue<T>::size_type>
class pw::FixedLockFreeSpscQueue< T, kInlineCapacity, SizeType >

Single-producer, single-consumer (SPSC) lock-free queue with integrated or owned storage, equivalent to pw::FixedQueue.

When kInlineCapacity is specified, FixedLockFreeSpscQueue statically allocates its storage buffer inline. When kInlineCapacity is omitted (or set to containers::kExternalStorage), the external-storage specialization is used, which supports dynamic allocation via Allocate() / TryAllocate(), ownership transfer via WithStorage(), or unowned external buffers. Both specializations inherit from LockFreeSpscQueue<T, SizeType> and can be used through a capacity-erased LockFreeSpscQueue<T, SizeType>& reference.

Template Parameters
TThe type of elements stored in the queue.
kInlineCapacityThe maximum number of elements the queue can hold. If set to containers::kExternalStorage, the queue storage will be outside the object.
SizeTypeUnsigned integer type used to store sizes and indices.

thread safemaybe isr safemaybe nmi safemaybe

Inheritance diagram for pw::FixedLockFreeSpscQueue< T, kInlineCapacity, SizeType >:
pw::containers::StorageBase< kAlignment, kSizeBytes > pw::LockFreeSpscQueue< T, SizeType >

Public Member Functions

constexpr FixedLockFreeSpscQueue () noexcept
 
 FixedLockFreeSpscQueue (const FixedLockFreeSpscQueue &)=delete
 
FixedLockFreeSpscQueue & operator= (const FixedLockFreeSpscQueue &)=delete
 
 FixedLockFreeSpscQueue (FixedLockFreeSpscQueue &&other) noexcept
 
FixedLockFreeSpscQueue & operator= (FixedLockFreeSpscQueue &&other) noexcept
 
template<size_t kOtherCapacity, typename = std::enable_if_t<(kOtherCapacity < kInlineCapacity)>>
 FixedLockFreeSpscQueue (FixedLockFreeSpscQueue< T, kOtherCapacity, SizeType > &&other) noexcept
 
template<size_t kOtherCapacity, typename = std::enable_if_t<(kOtherCapacity < kInlineCapacity)>>
FixedLockFreeSpscQueue & operator= (FixedLockFreeSpscQueue< T, kOtherCapacity, SizeType > &&other) noexcept
 
constexpr Deallocator * deallocator () const noexcept
 
- Public Member Functions inherited from pw::LockFreeSpscQueue< T, SizeType >
constexpr LockFreeSpscQueue (span< std::byte > unaligned_buffer) noexcept
 
template<size_t kAlignment, size_t kSizeBytes>
constexpr LockFreeSpscQueue (containers::Storage< kAlignment, kSizeBytes > &storage) noexcept
 
 LockFreeSpscQueue (const LockFreeSpscQueue &)=delete
 
LockFreeSpscQueue & operator= (const LockFreeSpscQueue &)=delete
 
 LockFreeSpscQueue (LockFreeSpscQueue &&)=delete
 
LockFreeSpscQueue & operator= (LockFreeSpscQueue &&)=delete
 
 ~LockFreeSpscQueue ()
 
reference front ()
 
const_reference front () const
 
pointer try_peek () noexcept
 
const_pointer try_peek () const noexcept
 
bool empty () const noexcept
 
bool full () const noexcept
 
size_type size () const noexcept
 
constexpr size_type capacity () const noexcept
 
constexpr size_type max_size () const noexcept
 
size_type remaining_capacity () const noexcept
 
void clear () noexcept
 
void push (const value_type &value)
 
void push (value_type &&value)
 
bool try_push (const value_type &value)
 
bool try_push (value_type &&value)
 
template<typename... Args>
void emplace (Args &&... args)
 
template<typename... Args>
bool try_emplace (Args &&... args)
 
void pop ()
 
std::optional< value_type > try_pop ()
 
bool try_pop (value_type &out)
 
WriteTransaction BeginWrite () noexcept
 
ReadTransaction BeginRead () noexcept
 
size_type push_some (span< const value_type > items)
 
size_type move_push_some (span< value_type > items)
 
bool try_push_all (span< const value_type > items)
 
bool try_move_push_all (span< value_type > items)
 
size_type pop_some (span< value_type > dest)
 
size_type pop_n (size_type count) noexcept
 

Additional Inherited Members

- Public Types inherited from pw::LockFreeSpscQueue< T, SizeType >
using value_type = T
 The type of elements stored in the queue.
 
using size_type = SizeType
 Unsigned integer type used for indexing and sizes.
 
using difference_type = ptrdiff_t
 Signed integer type for pointer differences.
 
using reference = value_type &
 Mutable reference to an element.
 
using const_reference = const value_type &
 Const reference to an element.
 
using pointer = value_type *
 Pointer to an element.
 
using const_pointer = const value_type *
 Const pointer to an element.
 
- Static Public Attributes inherited from pw::LockFreeSpscQueue< T, SizeType >
static constexpr size_type kMaxCapacity
 

Constructor & Destructor Documentation

◆ FixedLockFreeSpscQueue() [1/3]

template<typename T , size_t kInlineCapacity = containers::kExternalStorage, typename SizeType = typename LockFreeSpscQueue<T>::size_type>
constexpr pw::FixedLockFreeSpscQueue< T, kInlineCapacity, SizeType >::FixedLockFreeSpscQueue ( )
inlineconstexprnoexcept

Constructs an empty FixedLockFreeSpscQueue with internal, statically allocated storage.

thread safeyes isr safeyes nmi safeyes

◆ FixedLockFreeSpscQueue() [2/3]

template<typename T , size_t kInlineCapacity = containers::kExternalStorage, typename SizeType = typename LockFreeSpscQueue<T>::size_type>
pw::FixedLockFreeSpscQueue< T, kInlineCapacity, SizeType >::FixedLockFreeSpscQueue ( FixedLockFreeSpscQueue< T, kInlineCapacity, SizeType > &&  other)
inlinenoexcept

Move-constructs a FixedLockFreeSpscQueue from another queue of equal capacity.

Precondition
Neither *this nor other may be accessed concurrently during the move.
Parameters
[in]otherThe queue to move elements from.

thread safeno isr safemaybe nmi safemaybe

◆ FixedLockFreeSpscQueue() [3/3]

template<typename T , size_t kInlineCapacity = containers::kExternalStorage, typename SizeType = typename LockFreeSpscQueue<T>::size_type>
template<size_t kOtherCapacity, typename = std::enable_if_t<(kOtherCapacity < kInlineCapacity)>>
pw::FixedLockFreeSpscQueue< T, kInlineCapacity, SizeType >::FixedLockFreeSpscQueue ( FixedLockFreeSpscQueue< T, kOtherCapacity, SizeType > &&  other)
inlinenoexcept

Move-constructs from a FixedLockFreeSpscQueue of smaller inline capacity.

Precondition
Neither *this nor other may be accessed concurrently during the move.
Parameters
[in]otherThe queue to move elements from.

thread safeno isr safemaybe nmi safemaybe

Member Function Documentation

◆ deallocator()

template<typename T , size_t kInlineCapacity = containers::kExternalStorage, typename SizeType = typename LockFreeSpscQueue<T>::size_type>
constexpr Deallocator * pw::FixedLockFreeSpscQueue< T, kInlineCapacity, SizeType >::deallocator ( ) const
inlineconstexprnoexcept

Returns nullptr; a FixedLockFreeSpscQueue with static storage never allocates.

thread safeyes isr safeyes nmi safeyes

◆ operator=() [1/2]

template<typename T , size_t kInlineCapacity = containers::kExternalStorage, typename SizeType = typename LockFreeSpscQueue<T>::size_type>
FixedLockFreeSpscQueue & pw::FixedLockFreeSpscQueue< T, kInlineCapacity, SizeType >::operator= ( FixedLockFreeSpscQueue< T, kInlineCapacity, SizeType > &&  other)
inlinenoexcept

Move-assigns a FixedLockFreeSpscQueue from another queue of equal capacity.

Precondition
Neither *this nor other may be accessed concurrently during the move.
Parameters
[in]otherThe queue to move elements from.
Returns
A reference to *this.

thread safeno isr safemaybe nmi safemaybe

◆ operator=() [2/2]

template<typename T , size_t kInlineCapacity = containers::kExternalStorage, typename SizeType = typename LockFreeSpscQueue<T>::size_type>
template<size_t kOtherCapacity, typename = std::enable_if_t<(kOtherCapacity < kInlineCapacity)>>
FixedLockFreeSpscQueue & pw::FixedLockFreeSpscQueue< T, kInlineCapacity, SizeType >::operator= ( FixedLockFreeSpscQueue< T, kOtherCapacity, SizeType > &&  other)
inlinenoexcept

Move-assigns from a FixedLockFreeSpscQueue of smaller inline capacity.

Precondition
Neither *this nor other may be accessed concurrently during the move.
Parameters
[in]otherThe queue to move elements from.
Returns
A reference to *this.

thread safeno isr safemaybe nmi safemaybe


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