implements a lock free queue (i.e. container with FIFO order) of elements of type T with a maximum capacity MaxCapacity. The capacity can be defined to be anything between 0 and MaxCapacity at construction time or later at runtime using setCapacity. This is even possible while concurrent push and pop operations are executed, i.e. the queue does not have to be empty. Only one thread will succeed setting its desired capacity if there are more threads trying to change the capacity at the same time (it is unpredictable which thread).
More...
#include <iceoryx_hoofs/concurrent/resizeable_lockfree_queue.hpp>
|
using | element_t = ElementType |
|
|
| ResizeableLockFreeQueue (const ResizeableLockFreeQueue &)=delete |
|
| ResizeableLockFreeQueue (ResizeableLockFreeQueue &&)=delete |
|
ResizeableLockFreeQueue & | operator= (const ResizeableLockFreeQueue &)=delete |
|
ResizeableLockFreeQueue & | operator= (ResizeableLockFreeQueue &&)=delete |
|
| ResizeableLockFreeQueue (const uint64_t initialCapacity) noexcept |
|
uint64_t | capacity () const noexcept |
| returns the current capacity of the queue 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...
|
|
template<typename Function , typename = typename std::enable_if<cxx::is_invocable<Function, ElementType>::value>::type> |
bool | setCapacity (const uint64_t newCapacity, Function &&removeHandler) noexcept |
| Set the capacity to some value. More...
|
|
bool | setCapacity (const uint64_t newCapacity) noexcept |
| Set the capacity to a new capacity between 0 and MaxCapacity, if the capacity is reduced it may be necessary to remove the least recent elements which are then discarded. More...
|
|
|
static constexpr uint64_t | maxCapacity () noexcept |
| returns the maximum capacity of the queue More...
|
|
|
static constexpr uint64_t | MAX_CAPACITY = MaxCapacity |
|
|
using | Queue = IndexQueue< Capacity > |
|
using | BufferIndex = typename Queue::value_t |
|
using | element_t = ElementType |
|
void | writeBufferAt (const BufferIndex &, T &&) noexcept |
|
iox::cxx::optional< ElementType > | pushImpl (T &&value) noexcept |
|
cxx::optional< ElementType > | readBufferAt (const BufferIndex &) noexcept |
|
| LockFreeQueue () noexcept |
| creates and initalizes an empty LockFreeQueue
|
|
| LockFreeQueue (const LockFreeQueue &)=delete |
|
| LockFreeQueue (LockFreeQueue &&)=delete |
|
LockFreeQueue & | operator= (const LockFreeQueue &)=delete |
|
LockFreeQueue & | operator= (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...
|
|
Queue | m_freeIndices |
|
Queue | m_usedIndices |
|
Buffer< ElementType, Capacity, BufferIndex > | m_buffer |
|
std::atomic< uint64_t > | m_size |
|
template<typename ElementType, uint64_t MaxCapacity>
class iox::concurrent::ResizeableLockFreeQueue< ElementType, MaxCapacity >
implements a lock free queue (i.e. container with FIFO order) of elements of type T with a maximum capacity MaxCapacity. The capacity can be defined to be anything between 0 and MaxCapacity at construction time or later at runtime using setCapacity. This is even possible while concurrent push and pop operations are executed, i.e. the queue does not have to be empty. Only one thread will succeed setting its desired capacity if there are more threads trying to change the capacity at the same time (it is unpredictable which thread).
◆ capacity()
template<typename ElementType , uint64_t MaxCapacity>
returns the current capacity of the queue
- Returns
- the current capacity
- Note
- threadsafe, lockfree
◆ maxCapacity()
template<typename ElementType , uint64_t MaxCapacity>
returns the maximum capacity of the queue
- Returns
- the maximum capacity
◆ push() [1/2]
template<typename ElementType , uint64_t MaxCapacity>
inserts value in FIFO order, always succeeds by removing the oldest value when the queue is detected to be full (overflow)
- Parameters
-
[in] | value | to 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 MaxCapacity>
inserts value in FIFO order, always succeeds by removing the oldest value when the queue is detected to be full (overflow)
- Parameters
-
[in] | value | to be inserted is moved into the queue if possible |
- Returns
- removed value if an overflow occured, empty optional otherwise
- Note
- threadsafe, lockfree
◆ setCapacity() [1/2]
template<typename ElementType , uint64_t MaxCapacity>
Set the capacity to a new capacity between 0 and MaxCapacity, if the capacity is reduced it may be necessary to remove the least recent elements which are then discarded.
- Parameters
-
[in] | newCapacity | new capacity to be set, if it is larger than MaxCapacity the call fails |
- Returns
- true setting if the new capacity was successful, false otherwise (newCapacity > MaxCapacity)
- Note
- threadsafe, lockfree but multiple concurrent calls may have no effect
◆ setCapacity() [2/2]
template<typename ElementType , uint64_t MaxCapacity>
template<typename Function , typename = typename std::enable_if<cxx::is_invocable<Function, ElementType>::value>::type>
Set the capacity to some value.
- Note
- setCapacity is lockfree, but if an application crashes during setCapacity it currently may prevent other applications from setting the capacity (they will not block though). This is not a problem if for example there is only one application calling setCapacity or setCapacity is only called from vital applications (which if they crash will lead to system shutdown) and there is only one (non-vital, i.e. allowed to crash) application reading the data via pop. The reader application may also call setCapacity, since if it crashes there is no one reading the data and the capacity can be considered meaningless.
- Parameters
-
[in] | newCapacity | capacity to be set |
[in] | removeHandler | is a function taking an element which specifies what to do with removed elements should the need for removal arise. |
- Returns
- true if the capacity was successfully set, false otherwise
The documentation for this class was generated from the following file: