Skip to content

iox::concurrent::CyclicIndex🔗

index structure that can contain logical values 0, ..., CycleLength-1 but also stores an internal cycle counter to be used in compare_exchange More...

#include <cyclic_index.hpp>

Public Types🔗

Name
using ValueType value_t

Public Functions🔗

Name
CyclicIndex(ValueType value =0U)
CyclicIndex(ValueType index, ValueType cycle)
CyclicIndex(const CyclicIndex & ) =default
CyclicIndex(CyclicIndex && ) =default
CyclicIndex & operator=(const CyclicIndex & ) =default
CyclicIndex & operator=(CyclicIndex && ) =default
ValueType getIndex() const
ValueType getCycle() const
ValueType getValue() const
CyclicIndex operator+(const ValueType value) const
CyclicIndex next() const
bool isOneCycleBehind(const CyclicIndex & other) const
int64_t operator-(const CyclicIndex< CycleLength, ValueType > & rhs) const

Public Attributes🔗

Name
constexpr ValueType MAX_INDEX
constexpr ValueType MAX_VALUE
constexpr ValueType MAX_CYCLE
constexpr ValueType INDEX_AT_MAX_VALUE
constexpr ValueType OVERFLOW_START_INDEX

Detailed Description🔗

template <uint64_t CycleLength,
typename ValueType  =uint64_t>
class iox::concurrent::CyclicIndex;

index structure that can contain logical values 0, ..., CycleLength-1 but also stores an internal cycle counter to be used in compare_exchange

Public Types Documentation🔗

using value_t🔗

using iox::concurrent::CyclicIndex< CycleLength, ValueType >::value_t =  ValueType;

Public Functions Documentation🔗

function CyclicIndex🔗

explicit CyclicIndex(
    ValueType value =0U
)

function CyclicIndex🔗

CyclicIndex(
    ValueType index,
    ValueType cycle
)

function CyclicIndex🔗

CyclicIndex(
    const CyclicIndex & 
) =default

function CyclicIndex🔗

CyclicIndex(
    CyclicIndex && 
) =default

function operator=🔗

CyclicIndex & operator=(
    const CyclicIndex & 
) =default

function operator=🔗

CyclicIndex & operator=(
    CyclicIndex && 
) =default

function getIndex🔗

ValueType getIndex() const

function getCycle🔗

ValueType getCycle() const

function getValue🔗

ValueType getValue() const

function operator+🔗

CyclicIndex operator+(
    const ValueType value
) const

function next🔗

CyclicIndex next() const

function isOneCycleBehind🔗

bool isOneCycleBehind(
    const CyclicIndex & other
) const

function operator-🔗

int64_t operator-(
    const CyclicIndex< CycleLength, ValueType > & rhs
) const

Note: The difference will be negative if lhs < rhs (lhs is this) and its absolute value fits into an int64_t, otherwise it will be positive and follow the rules of modular arithmetic of unsigned types This is intended and includes the case were rhs is "very close to 0" and and lhs is "close" to the MAX of uint64_t (MAX=2^64-1). Here close means that the real absolute difference would be larger than 2^63. This is excactly the right behaviour to deal with a (theoretically possible) overflow of lhs and can be seen as lhs being interpreted as MAX + its actual value. In this case, lhs - rhs is positive even though lhs < rhs.

Public Attributes Documentation🔗

variable MAX_INDEX🔗

static constexpr ValueType MAX_INDEX = CycleLength - 1U;

variable MAX_VALUE🔗

static constexpr ValueType MAX_VALUE = std::numeric_limits<ValueType>::max();

variable MAX_CYCLE🔗

static constexpr ValueType MAX_CYCLE = MAX_VALUE / CycleLength;

variable INDEX_AT_MAX_VALUE🔗

static constexpr ValueType INDEX_AT_MAX_VALUE = MAX_VALUE % CycleLength;

variable OVERFLOW_START_INDEX🔗

static constexpr ValueType OVERFLOW_START_INDEX = (INDEX_AT_MAX_VALUE + 1U) % CycleLength;

Updated on 31 May 2022 at 15:29:15 CEST