iceoryx_hoofs 2.0.3
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
iox::concurrent::LockFreeQueue< ElementType, Capacity > Class Template Reference

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

using element_t = ElementType
 

Public Member Functions

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

Protected Types

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

Protected Member Functions

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

Protected Attributes

Queue m_freeIndices
 
Queue m_usedIndices
 
Buffer< ElementType, Capacity, BufferIndex > m_buffer
 
std::atomic< uint64_t > m_size {0u}
 

Detailed Description

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

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

Member Function Documentation

◆ capacity()

template<typename ElementType , uint64_t Capacity>
constexpr uint64_t iox::concurrent::LockFreeQueue< ElementType, Capacity >::capacity ( ) const
constexprnoexcept

returns the capacity of the queue

Note
threadsafe, lockfree

◆ empty()

template<typename ElementType , uint64_t Capacity>
bool iox::concurrent::LockFreeQueue< ElementType, Capacity >::empty ( ) const
noexcept

check whether the queue is empty

Returns
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

◆ pop()

template<typename ElementType , uint64_t Capacity>
iox::cxx::optional< ElementType > iox::concurrent::LockFreeQueue< ElementType, Capacity >::pop ( )
noexcept

tries to remove value in FIFO order

Returns
value if removal was successful, empty optional otherwise
Note
threadsafe, lockfree

◆ push() [1/2]

template<typename ElementType , uint64_t Capacity>
iox::cxx::optional< ElementType > iox::concurrent::LockFreeQueue< ElementType, Capacity >::push ( const ElementType &  value)
noexcept

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

Parameters
valueto be inserted is copied into the queue
Returns
removed value if an overflow occured, empty optional otherwise
Note
threadsafe, lockfree

◆ push() [2/2]

template<typename ElementType , uint64_t Capacity>
iox::cxx::optional< ElementType > iox::concurrent::LockFreeQueue< ElementType, Capacity >::push ( ElementType &&  value)
noexcept

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

Parameters
valueto be inserted is moved into the queue if possible
Returns
removed value if an overflow occured, empty optional otherwise
Note
threadsafe, lockfree

◆ size()

template<typename ElementType , uint64_t Capacity>
uint64_t iox::concurrent::LockFreeQueue< ElementType, Capacity >::size ( ) const
noexcept

get the number of stored elements in the queue

Returns
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

◆ tryPush() [1/2]

template<typename ElementType , uint64_t Capacity>
bool iox::concurrent::LockFreeQueue< ElementType, Capacity >::tryPush ( const ElementType &  value)
noexcept

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

Parameters
valueto be inserted
Returns
true if insertion was successful (i.e. queue was not full during push), false otherwise
Note
threadsafe, lockfree

◆ tryPush() [2/2]

template<typename ElementType , uint64_t Capacity>
bool iox::concurrent::LockFreeQueue< ElementType, Capacity >::tryPush ( ElementType &&  value)
noexcept

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

Parameters
valueto be inserted
Returns
true if insertion was successful (i.e. queue was not full during push), false otherwise
Note
threadsafe, lockfree

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