quill
Classes | Public Member Functions | List of all members
detail::UnboundedSPSCQueue Class Reference

A single-producer single-consumer FIFO circular buffer. More...

#include <UnboundedSPSCQueue.h>

Classes

struct  ReadResult
 

Public Member Functions

 UnboundedSPSCQueue (size_t initial_bounded_queue_capacity, size_t max_capacity, HugePagesPolicy huge_pages_policy=quill::HugePagesPolicy::Never)
 Constructor.
 
 UnboundedSPSCQueue (UnboundedSPSCQueue const &)=delete
 Deleted.
 
UnboundedSPSCQueueoperator= (UnboundedSPSCQueue const &)=delete
 
 ~UnboundedSPSCQueue ()
 Destructor.
 
QUILL_NODISCARD QUILL_ATTRIBUTE_HOT std::byte * prepare_write (size_t nbytes)
 Reserve contiguous space for the producer without making it visible to the consumer. More...
 
QUILL_ATTRIBUTE_HOT void finish_write (size_t nbytes) noexcept
 Complement to reserve producer space that makes nbytes starting from the return of reserve producer space visible to the consumer.
 
QUILL_ATTRIBUTE_HOT void commit_write () noexcept
 Commit write to notify the consumer bytes are ready to read.
 
QUILL_ATTRIBUTE_HOT void finish_and_commit_write (size_t nbytes) noexcept
 Finish and commit write as a single function.
 
QUILL_NODISCARD size_t producer_capacity () const noexcept
 Return the current buffer's capacity. More...
 
void shrink (size_t capacity)
 Shrinks the queue if capacity is a valid smaller power of 2. More...
 
QUILL_NODISCARD QUILL_ATTRIBUTE_HOT ReadResult prepare_read ()
 Prepare to read from the buffer a callback used for notifications to the user. More...
 
QUILL_ATTRIBUTE_HOT void finish_read (size_t nbytes) noexcept
 Consumes the next nbytes in the buffer and frees it back for the producer to reuse.
 
QUILL_ATTRIBUTE_HOT void commit_read () noexcept
 Commit the read to indicate that the bytes are read and are now free to be reused.
 
QUILL_NODISCARD size_t capacity () const noexcept
 Return the current buffer's capacity. More...
 
QUILL_NODISCARD QUILL_ATTRIBUTE_HOT bool empty () const noexcept
 checks if the queue is empty More...
 

Detailed Description

A single-producer single-consumer FIFO circular buffer.

The buffer allows producing and consuming objects

Production is wait free.

When the internal circular buffer becomes full a new one will be created and the production will continue in the new buffer.

Consumption is wait free. If not data is available a special value is returned. If a new buffer is created from the producer the consumer first consumes everything in the old buffer and then moves to the new buffer.

Member Function Documentation

◆ capacity()

QUILL_NODISCARD size_t detail::UnboundedSPSCQueue::capacity ( ) const
inlinenoexcept

Return the current buffer's capacity.

Note
: consumer only
Returns
capacity

◆ empty()

QUILL_NODISCARD QUILL_ATTRIBUTE_HOT bool detail::UnboundedSPSCQueue::empty ( ) const
inlinenoexcept

checks if the queue is empty

Note
consumer only
Returns
true if empty, false otherwise

◆ prepare_read()

QUILL_NODISCARD QUILL_ATTRIBUTE_HOT ReadResult detail::UnboundedSPSCQueue::prepare_read ( )
inline

Prepare to read from the buffer a callback used for notifications to the user.

Returns
first: pointer to buffer or nullptr, second: a pair of new_capacity, previous_capacity if an allocation

◆ prepare_write()

QUILL_NODISCARD QUILL_ATTRIBUTE_HOT std::byte* detail::UnboundedSPSCQueue::prepare_write ( size_t  nbytes)
inline

Reserve contiguous space for the producer without making it visible to the consumer.

Returns
a valid point to the buffer

◆ producer_capacity()

QUILL_NODISCARD size_t detail::UnboundedSPSCQueue::producer_capacity ( ) const
inlinenoexcept

Return the current buffer's capacity.

Note
: producer only
Returns
capacity

◆ shrink()

void detail::UnboundedSPSCQueue::shrink ( size_t  capacity)
inline

Shrinks the queue if capacity is a valid smaller power of 2.

Parameters
capacityNew target capacity.
Note
: producer (frontend) is safe to call this - Do not call on the consumer (the backend worker)

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