Skip to content

iox::concurrent::LockFreeQueue🔗

implements a lock free queue (i.e. container with FIFO order) of elements of type T with a fixed Capacity More...

#include <iceoryx_hoofs/concurrent/lockfree_queue.hpp>

Public Types🔗

Name
using ElementType element_t

Protected Types🔗

Name
using IndexQueue< Capacity > Queue
using typename Queue::value_t BufferIndex

Public Functions🔗

Name
LockFreeQueue()
creates and initalizes an empty LockFreeQueue
~LockFreeQueue() =default
LockFreeQueue(const LockFreeQueue & )
LockFreeQueue(LockFreeQueue && )
LockFreeQueue & operator=(const LockFreeQueue & )
LockFreeQueue & operator=(LockFreeQueue && )
constexpr uint64_t capacity() const
returns the capacity of the queue
bool tryPush(ElementType && value)
tries to insert value in FIFO order, moves the value internally
bool tryPush(const ElementType & value)
tries to insert value in FIFO order, copies the value internally
iox::cxx::optional< ElementType > push(const ElementType & value)
inserts value in FIFO order, always succeeds by removing the oldest value when the queue is detected to be full (overflow)
iox::cxx::optional< ElementType > push(ElementType && value)
inserts value in FIFO order, always succeeds by removing the oldest value when the queue is detected to be full (overflow)
iox::cxx::optional< ElementType > pop()
tries to remove value in FIFO order
bool empty() const
check whether the queue is empty
uint64_t size() const
get the number of stored elements in the queue

Protected Functions🔗

Name
template <typename T >
void
writeBufferAt(const BufferIndex & , T && )
template <typename T >
iox::cxx::optional< ElementType >
pushImpl(T && value)
cxx::optional< ElementType > readBufferAt(const BufferIndex & )

Protected Attributes🔗

Name
Queue m_freeIndices
Queue m_usedIndices
Buffer< ElementType, Capacity, BufferIndex > m_buffer
std::atomic< uint64_t > m_size

Detailed Description🔗

template <typename ElementType ,
uint64_t Capacity>
class iox::concurrent::LockFreeQueue;

implements a lock free queue (i.e. container with FIFO order) of elements of type T with a fixed Capacity

Public Types Documentation🔗

using element_t🔗

using iox::concurrent::LockFreeQueue< ElementType, Capacity >::element_t =  ElementType;

Protected Types Documentation🔗

using Queue🔗

using iox::concurrent::LockFreeQueue< ElementType, Capacity >::Queue =  IndexQueue<Capacity>;

using BufferIndex🔗

using iox::concurrent::LockFreeQueue< ElementType, Capacity >::BufferIndex =  typename Queue::value_t;

Public Functions Documentation🔗

function LockFreeQueue🔗

LockFreeQueue()

creates and initalizes an empty LockFreeQueue

function ~LockFreeQueue🔗

~LockFreeQueue() =default

function LockFreeQueue🔗

LockFreeQueue(
    const LockFreeQueue & 
)

function LockFreeQueue🔗

LockFreeQueue(
    LockFreeQueue && 
)

function operator=🔗

LockFreeQueue & operator=(
    const LockFreeQueue & 
)

function operator=🔗

LockFreeQueue & operator=(
    LockFreeQueue && 
)

function capacity🔗

constexpr uint64_t capacity() const

returns the capacity of the queue

Note: threadsafe, lockfree

function tryPush🔗

bool tryPush(
    ElementType && value
)

tries to insert value in FIFO order, moves the value internally

Parameters:

  • value to be inserted

Return: true if insertion was successful (i.e. queue was not full during push), false otherwise

Note: threadsafe, lockfree

function tryPush🔗

bool tryPush(
    const ElementType & value
)

tries to insert value in FIFO order, copies the value internally

Parameters:

  • value to be inserted

Return: true if insertion was successful (i.e. queue was not full during push), false otherwise

Note: threadsafe, lockfree

function push🔗

iox::cxx::optional< ElementType > push(
    const ElementType & value
)

inserts value in FIFO order, always succeeds by removing the oldest value when the queue is detected to be full (overflow)

Parameters:

  • value to be inserted is copied into the queue

Return: removed value if an overflow occured, empty optional otherwise

Note: threadsafe, lockfree

function push🔗

iox::cxx::optional< ElementType > push(
    ElementType && value
)

inserts value in FIFO order, always succeeds by removing the oldest value when the queue is detected to be full (overflow)

Parameters:

  • value to be inserted is moved into the queue if possible

Return: removed value if an overflow occured, empty optional otherwise

Note: threadsafe, lockfree

function pop🔗

iox::cxx::optional< ElementType > pop()

tries to remove value in FIFO order

Return: value if removal was successful, empty optional otherwise

Note: threadsafe, lockfree

function empty🔗

bool empty() const

check whether the queue is empty

Return: true iff the queue is empty

Note:

  • that if the queue is used concurrently it might not be empty anymore after the call (but it was at some point during the call)
  • threadsafe, lockfree

function size🔗

uint64_t size() const

get the number of stored elements in the queue

Return: number of stored elements in the queue

Note:

  • that this will not be perfectly in sync with the actual number of contained elements during concurrent operation but will always be at most capacity
  • threadsafe, lockfree

Protected Functions Documentation🔗

function writeBufferAt🔗

template <typename T >
void writeBufferAt(
    const BufferIndex & ,
    T && 
)

function pushImpl🔗

template <typename T >
iox::cxx::optional< ElementType > pushImpl(
    T && value
)

function readBufferAt🔗

cxx::optional< ElementType > readBufferAt(
    const BufferIndex & 
)

Protected Attributes Documentation🔗

variable m_freeIndices🔗

Queue m_freeIndices;

variable m_usedIndices🔗

Queue m_usedIndices;

variable m_buffer🔗

Buffer< ElementType, Capacity, BufferIndex > m_buffer;

variable m_size🔗

std::atomic< uint64_t > m_size {0u};

Updated on 2 April 2022 at 16:37:47 CEST