Thread safe producer and consumer queue with a safe overflowing behavior. SoFi is designed in a FIFO Manner but prevents data loss when pushing into a full SoFi. When SoFi is full and a Sender tries to push, the data at the current read position will be returned. SoFi is a Thread safe without using locks. When the buffer is filled, new data is written starting at the beginning of the buffer and overwriting the old.The SoFi is especially designed to provide fixed capacity storage. When its capacity is exhausted, newly inserted elements will cause elements either at the beginning to be overwritten.The SoFi only allocates memory when created , capacity can be is adjusted explicitly.
More...
#include <sofi.hpp>
|
| SoFi () noexcept |
| default constructor which constructs an empty sofi
|
|
bool | push (const ValueType &valueOut, ValueType &f_paramOut_r) noexcept |
| pushs an element into sofi. if sofi is full the oldest data will be returned and the pushed element is stored in its place instead. More...
|
|
bool | pop (ValueType &valueOut) noexcept |
| pop the oldest element More...
|
|
template<typename Verificator_T > |
bool | popIf (ValueType &valueOut, const Verificator_T &verificator) noexcept |
| conditional pop call to provide an alternative for a peek and pop approach. If the verificator returns true the peeked element is returned. More...
|
|
bool | empty () const noexcept |
| returns true if sofi is empty, otherwise false More...
|
|
bool | setCapacity (const uint64_t newSize) noexcept |
| resizes sofi More...
|
|
uint64_t | capacity () const noexcept |
| returns the capacity of sofi More...
|
|
uint64_t | size () const noexcept |
| returns the current size of sofi More...
|
|
template<class ValueType, uint64_t CapacityValue>
class iox::concurrent::SoFi< ValueType, CapacityValue >
Thread safe producer and consumer queue with a safe overflowing behavior. SoFi is designed in a FIFO Manner but prevents data loss when pushing into a full SoFi. When SoFi is full and a Sender tries to push, the data at the current read position will be returned. SoFi is a Thread safe without using locks. When the buffer is filled, new data is written starting at the beginning of the buffer and overwriting the old.The SoFi is especially designed to provide fixed capacity storage. When its capacity is exhausted, newly inserted elements will cause elements either at the beginning to be overwritten.The SoFi only allocates memory when created , capacity can be is adjusted explicitly.
- Parameters
-
[in] | ValueType | DataType to be stored, must be trivially copyable |
[in] | CapacityValue | Capacity of the SoFi |
◆ capacity()
template<class ValueType , uint64_t CapacityValue>
returns the capacity of sofi
- Concurrent:
- unrestricted thread safe
◆ empty()
template<class ValueType , uint64_t CapacityValue>
returns true if sofi is empty, otherwise false
- Note
- the use of this function is limited in the concurrency case. if you call this and in another thread pop is called the result can be out of date as soon as you require it
- Concurrent:
- unrestricted thread safe
- Todo:
- read before write since the writer increments the aba counter!!!
- Todo:
- write doc with example!!!
◆ pop()
template<class ValueType , uint64_t CapacityValue>
pop the oldest element
- Parameters
-
[out] | valueOut | storage of the pop'ed value |
- Concurrent:
- restricted thread safe: single pop, single push no pop or popIf calls from multiple contexts
- Returns
- false if sofi is empty, otherwise true
◆ popIf()
template<class ValueType , uint64_t CapacityValue>
template<typename Verificator_T >
bool iox::concurrent::SoFi< ValueType, CapacityValue >::popIf |
( |
ValueType & |
valueOut, |
|
|
const Verificator_T & |
verificator |
|
) |
| |
|
inlinenoexcept |
conditional pop call to provide an alternative for a peek and pop approach. If the verificator returns true the peeked element is returned.
- Parameters
-
[out] | valueOut | storage of the pop'ed value |
[in] | verificator | callable of type bool(const ValueType& peekValue) which takes the value which would be pop'ed as argument and returns true if it should be pop'ed, otherwise false int limit = 7128;
mysofi.popIf(value, [=](const ValueType & peek)
{
return peek < limit;
}
);
|
- Concurrent:
- restricted thread safe: single pop, single push no pop or popIf calls from multiple contexts
- Returns
- false if sofi is empty or when verificator returns false, otherwise true
first we need to peak valueOut if it is fitting the condition and then we have to verify if valueOut is not am invalid object, this could be the case if the read position has changed
◆ push()
template<class ValueType , uint64_t CapacityValue>
bool iox::concurrent::SoFi< ValueType, CapacityValue >::push |
( |
const ValueType & |
valueOut, |
|
|
ValueType & |
f_paramOut_r |
|
) |
| |
|
noexcept |
pushs an element into sofi. if sofi is full the oldest data will be returned and the pushed element is stored in its place instead.
- Parameters
-
[in] | valueOut | value which should be stored |
[out] | f_paramOut_r | if sofi is overflowing the value of the overridden value is stored here |
- Concurrent:
- restricted thread safe: single pop, single push no push calls from multiple contexts
- Returns
- return true if push was sucessfull else false.
(initial situation, SOFI is FULL)
Start|-----A-------|
|-----B-------|
|-----C-------|
|-----D-------|
(calling
push with data āEā)
Start|-----E-------|
|-----A-------|
|-----B-------|
|-----C-------|
(āDā is returned as value_out)
###################################################################
(
if SOFI is not FULL , calling
push() add
new data)
Start|-------------|
|-------------| ( Initial SOFI )
(
push() Called two times)
|-------------|
(New Data)
|-------------|
(New Data)
bool push(const ValueType &valueOut, ValueType &f_paramOut_r) noexcept
pushs an element into sofi. if sofi is full the oldest data will be returned and the pushed element i...
Definition: sofi.inl:144
◆ setCapacity()
template<class ValueType , uint64_t CapacityValue>
resizes sofi
- Parameters
-
[in] | newSize | valid values are 0 < newSize < CapacityValue |
- Precondition
- it is important that no pop or push calls occur during this call
- Concurrent:
- not thread safe
◆ size()
template<class ValueType , uint64_t CapacityValue>
returns the current size of sofi
- Concurrent:
- unrestricted thread safe
The documentation for this class was generated from the following files:
- iceoryx_utils/internal/concurrent/sofi.hpp
- iceoryx_utils/internal/concurrent/sofi.inl