Overview / System & concurrency

resilience

Policies that wrap a call that can fail: retries, circuit breaker, concurrency limit and rate limit, composed in a fixed order.

Always compiled: part of the core build.Include #include <ethereal/cpp/resilience/resilience_inc.hpp>C layer

resilience_inc.hpp

#include <ethereal/cpp/resilience/resilience_inc.hpp>

Entry point of the Resilience module.

Policies that wrap a call that can go wrong: retry, circuit breaker, concurrency limit, rate limit, and their composition into a chain. Including this header brings the whole module.

The policies wrap every outbound call, and over 99 percent of them succeed. The success path must cost almost nothing: no allocations on any path, composition resolved at compile time, and the closed breaker check reduced to one atomic load and one compare.

No default value retries. Retrying an operation that is not idempotent applies its effect twice, and the likeliest case is the one where the request arrived, was done, and the response was lost.

breaker.hpp

#include <ethereal/cpp/resilience/breaker.hpp>

Circuit breaker of the Resilience module.

When a service is down, calling it again helps nobody. Each call waits the whole timeout before failing, and the service gets load while it tries to recover.

Closed, calls pass. Open, calls are rejected at once without leaving the process. After a while, half open: a few calls pass as probes, and their results decide.

The closed state check is one relaxed atomic load and one compare ("Nothing else. No clock read, no window scan, no lock."). The clock is read only after a call ends, to record it, and on the open path, which is rare.

uMinimumCalls is not optional ("a breaker that trips on the first call of the process is a bug generator"). A 100 percent failure rate over one call means nothing, and without the minimum the first request of a fresh process, the one that meets a cold connection, would open the breaker for everyone.

enum

EBreakerState

Ethereal::Resilience#
C++
enum class   EBreakerState : ETL_UINT8
{
    /// @brief  Everything passes. The normal state.
    eClosed = 0,

    /// @brief  Everything is rejected at once.
    eOpen,

    /// @brief  A few calls pass as probes.
    eHalfOpen
};

State of a breaker.

function

BreakerStateName

Ethereal::Resilience#
const ETL_CHAR * BreakerStateName( EBreakerState eState ) noexcept;

Name of a breaker state, for messages.

eState
The state.
A static string. Never null.
enum

EBreakerTrigger

Ethereal::Resilience#
C++
enum class   EBreakerTrigger : ETL_UINT8
{
    /// @brief  Percentage of failures in the window.
    eFailureRate = 0,

    /// @brief  A number of failures in a row.
    eConsecutiveFailures,

    /// @brief  Percentage of slow calls in the window.
    ///
    /// @details  A slow service takes down its callers as well as a dead one,
    ///            and is harder to diagnose: calls do not fail, they hang.
    eSlowCallRate
};

What makes the breaker open.

const

kBucketCount

Ethereal::Resilience#
inline constexpr std::size_t kBucketCount = 10u;

Number of buckets in the sliding window.

Reading the rate is a loop over the buckets. A loop of ten fits in a cache line and runs without a break.

struct

SBreakerPolicy

Ethereal::Resilience#
C++
struct   SBreakerPolicy   final
{
    /// @brief  What opens the breaker.
    EBreakerTrigger        eTrigger = EBreakerTrigger::eFailureRate;

    /// @brief  Failure percentage that opens, as an integer. No floating point.
    ETL_UINT32            uFailureRatePercent = 50u;

    /// @brief  Below this many calls in the window the breaker never opens, whatever the rate.
    ETL_UINT32            uMinimumCalls = 20u;

    /// @brief  Failures in a row that open, with eConsecutiveFailures.
    ETL_UINT32            uConsecutiveFailures = 5u;

    /// @brief  From this duration on, a call counts as slow.
    ETL_UINT64            uSlowCallThresholdMs = 1000u;

    /// @brief  Slow call percentage that opens, with eSlowCallRate.
    ETL_UINT32            uSlowCallRatePercent = 50u;

    /// @brief  Time spent open before letting probes through.
    ETL_UINT64            uOpenDurationMs = 30000u;

    /// @brief  Number of probes allowed in half open.
    ETL_UINT32            uHalfOpenPermitted = 3u;

    /// @brief  Time covered by each bucket of the window.
    ETL_UINT64            uBucketDurationMs = 1000u;
};

Breaker configuration.

alias

void

Ethereal::Resilience#
using BreakerCallback = void ( * )( void * pCtx, EBreakerState eFrom, EBreakerState eTo );

Called when the state changes.

Called outside any critical section, after the change is done. A callback made while holding a lock invites the receiver to deadlock the process from inside.

class

CCircuitBreaker

Ethereal::Resilience#

Lets calls through, or not.

class CCircuitBreaker final
Thread safe. A breaker is shared by everyone calling the same service, and its value comes from seeing all the calls.
constructor

CCircuitBreaker

#
explicit CCircuitBreaker( const SBreakerPolicy & Policy = SBreakerPolicy(), IClock & Clock = SystemClock() ) noexcept;

Builds a closed breaker.

Policy
Breaker configuration.
Clock
Clock for the window and the open duration.
function

Acquire

#
EStatus Acquire() noexcept;

Asks whether a call may go out.

Closed, this is one relaxed load and one compare, and nothing else. It is the path of over 99 percent of calls.

eOk, or eOpen when rejected.
function

OnSuccess

#
void OnSuccess( const ETL_UINT64 uElapsedNs = 0 ) noexcept;

Records a successful call.

uElapsedNs
Duration of the call. Zero when not measured.
function

OnFailure

#
void OnFailure() noexcept;

Records a failed call.

function

Execute

#
template< typename F > EStatus Execute( F && Op ) noexcept

Wraps an operation: asks, runs, records.

A template so the chain can be inlined. Taking an SOperation here would erase the type of the next link, and the compiler would see one indirect call per policy, four unpredictable jumps on the success path. Measured: with the type erased, the chain of four cost 166 ns. Without it, the chain fits the target.

An SOperation still works here, since it is callable. That is how the runtime chain uses the same function.

Op
Callable returning EStatus.
The status of the operation, or eOpen when rejected.
function

NeedsClock

#
bool NeedsClock() const noexcept

true when recording a successful call needs the clock.

function

State

#
EBreakerState State() const noexcept;

Current state.

function

FailureRate

#
ETL_UINT32 FailureRate() const noexcept;

Failure rate of the window, as an integer percentage.

function

Stats

#
SPolicyStats Stats() const noexcept;

Counters of the policy.

function

ForceOpen

#
void ForceOpen() noexcept;

Opens, and stays open until told otherwise.

function

ForceClosed

#
void ForceClosed() noexcept;

Closes, and stays closed until told otherwise.

function

Reset

#
void Reset() noexcept;

Back to the start: closed, empty window, nothing forced.

function

SetCallback

#
void SetCallback( const BreakerCallback pFn, void * const pCtx ) noexcept

Sets the state change callback.

pFn
Callback. Null removes it.
pCtx
Context passed to the callback.

limits.hpp

#include <ethereal/cpp/resilience/limits.hpp>

Bulkhead and rate limiter of the Resilience module.

Two ways of saying "no more than this". The bulkhead counts how many calls run at the same time. The rate limiter counts how many start per second. They are often confused: a limit of ten per second does not stop a thousand in flight if each one takes a hundred seconds.

class

CBulkhead

Ethereal::Resilience#

Limits how many operations run at the same time.

class CBulkhead final

The name comes from ships: bulkheads split the hull so one breach does not sink the whole ship. Without a concurrency limit, a hundred requests to a service that takes a minute hold a hundred threads for a minute, and the process stops doing anything else, including work unrelated to that service.

The uncontended path is one atomic decrement and one compare. No lock.

Thread safe.
constructor

CBulkhead

#
explicit CBulkhead( const ETL_UINT32 uMaxConcurrent = 8u ) noexcept : m_iFree( static_cast< ETL_INT32 >( uMaxConcurrent ) ) , m_uMax( uMaxConcurrent )

Builds an empty bulkhead.

uMaxConcurrent
Maximum number of operations at the same time.
function

TryAcquire

#
EStatus TryAcquire() noexcept;

Tries to enter. Does not wait.

Rejecting at once is better than an unbounded queue. An unbounded queue turns a concurrency problem into a memory problem, and delays the bad news until it can no longer be handled.

eOk, or EStatus::eRejected when full.
function

Acquire

#
EStatus Acquire( const ETL_UINT64 uTimeoutMs ) noexcept;

Enters, waiting for a slot.

uTimeoutMs
Maximum wait. Zero does not wait. A deadline past the 64 bit limit saturates and waits with no end.
eOk, or eRejected on timeout.
function

Release

#
void Release() noexcept;

Leaves, freeing the slot.

function

Execute

#
template< typename F > EStatus Execute( F && Op ) noexcept

Wraps an operation: enters, runs, leaves. Always leaves.

A template, for the same reason as CCircuitBreaker::Execute.

Op
Callable returning EStatus.
The status of the operation, or eRejected.
function

Available

#
ETL_UINT32 Available() const noexcept;

Free slots now.

function

Capacity

#
ETL_UINT32 Capacity() const noexcept

Maximum number of operations at the same time.

function

Stats

#
SPolicyStats Stats() const noexcept;

Counters of the policy.

enum

EBucketKind

Ethereal::Resilience#
C++
enum class   EBucketKind : ETL_UINT8
{
    /// @brief  Accumulates up to the limit and lets the saved burst through.
    eToken = 0,

    /// @brief  Does not accumulate. The rate is all there is.
    eLeaky
};

How the credit behaves.

The token bucket lets a burst through, up to the bucket size, and then settles at the rate. The leaky bucket lets no burst through and spreads everything. Neither is better. One is for callers that must absorb bursts, the other for callers that must not cause them and take down a neighbor.

class

CRateLimiter

Ethereal::Resilience#

Limits how many operations start per unit of time.

class CRateLimiter final

Integer arithmetic only ("No floating point, no division in the hot path"). Floating point in a shared counter accumulates rounding error, and after a day the measured rate is not the configured one. The spec accuracy test (1 percent over sixty seconds) is only possible with integers.

Credit is kept in nano-tokens, 10^9 per token. Partial refills are not lost to rounding, and the math fits in 64 bit integers with no division on the hot path.

Thread safe.
constructor

CRateLimiter

#
explicit CRateLimiter( const ETL_UINT32 uPerSecond = 100u, const ETL_UINT32 uBurst = 0u, const EBucketKind eKind = EBucketKind::eToken, IClock & Clock = SystemClock() ) noexcept;

Builds a full limiter.

uPerSecond
Operations per second.
uBurst
How many can go together. Zero uses uPerSecond.
eKind
Token or leaky bucket.
Clock
Clock for the refill.
function

TryAcquire

#
EStatus TryAcquire( const ETL_UINT32 uTokens = 1u ) noexcept;

Tries to spend tokens. Does not wait.

uTokens
Tokens to spend.
eOk, or eThrottled.
function

Acquire

#
EStatus Acquire( const ETL_UINT32 uTokens, const ETL_UINT64 uTimeoutMs ) noexcept;

Spends tokens, waiting for them.

uTokens
Tokens to spend.
uTimeoutMs
Maximum wait. Zero does not wait. A deadline past the 64 bit limit saturates and waits with no end.
eOk, or eThrottled on timeout.
function

Execute

#
template< typename F > EStatus Execute( F && Op ) noexcept

Wraps an operation: spends one token and runs.

Op
Callable returning EStatus.
The status of the operation, or eThrottled.
function

Available

#
ETL_UINT32 Available() noexcept;

Tokens available now, refill included.

function

Stats

#
SPolicyStats Stats() const noexcept;

Counters of the policy.

pipeline.hpp

#include <ethereal/cpp/resilience/pipeline.hpp>

Policy composition of the Resilience module.

The order matters, and it is:

bulkhead -> breaker -> retry -> timeout -> the operation

The bulkhead goes outside because it protects the caller's threads. Inside the retry, three attempts of a thousand calls would take slots as if they were three thousand calls.

The breaker goes before the retry because an open breaker must cut the whole call. The other way around, each attempt would ask the breaker and an open breaker would return three rejections instead of one.

The timeout goes inside the retry because it limits each attempt. For the total there is already the retry budget.

Composition is resolved at compile time ("producing a single inlined call chain, not a runtime list of virtual 'IPolicy' objects"). A list of virtual policies costs one indirect call per policy on every call. With templates the compiler sees the whole chain and inlines it, and what is left is the breaker load and the bulkhead decrement. CRuntimePipeline is the list of objects, for compositions built from configuration. It is slower.

class

CTerminal

Ethereal::Resilience#

End of the chain: runs the operation.

class CTerminal final
function

Execute

#
template< typename F > EStatus Execute( F && Op ) const noexcept

Runs the operation.

Op
Callable returning EStatus.
The status of the operation.
function

MakePipeline

Ethereal::Resilience#
template< typename TPolicy > inline CLink< TPolicy, CTerminal > MakePipeline( TPolicy & Policy ) noexcept

Builds a chain of one policy.

Policy
The policy. Not owned.
The chain.
function

MakePipeline

Ethereal::Resilience#
template< typename TPolicy, typename... TRest > inline auto MakePipeline( TPolicy & Policy, TRest &... Rest ) noexcept

Builds a chain. The first policy is the outermost.

Policy
The outermost policy. Not owned.
Rest
The other policies, outside in. Not owned.
The chain.
class

IPolicy

Ethereal::Resilience#

What a policy can do, seen from outside.

class IPolicy
destructor

~IPolicy

#
virtual ~IPolicy() = default;

Destructor.

function

Execute

#
virtual EStatus Execute( const SOperation & Op ) noexcept = 0;

Runs the operation through the policy.

Op
The operation.
The status of the operation, or the policy's rejection.
class

CPolicyAdapter

Ethereal::Resilience#
template< typename TPolicy > class CPolicyAdapter final : public IPolicy
constructor

CPolicyAdapter

#
explicit CPolicyAdapter( TPolicy & Policy ) noexcept : m_pPolicy( &Policy )

Wraps the policy.

Policy
The policy. Not owned.
function

Execute

#
EStatus Execute( const SOperation & Op ) noexcept override

Runs the operation through the wrapped policy.

class

CRuntimePipeline

Ethereal::Resilience#

A chain built at run time.

class CRuntimePipeline final

Slower than the template chain, and documented as such. Each link costs an indirect call the processor cannot predict. It exists for compositions built from configuration, where the types are unknown at compile time.

Does not own the policies, and the capacity is fixed. A chain that allocated when built could not be built on a path that promises no allocations.

function

Add

#
bool Add( IPolicy * const pPolicy ) noexcept

Appends a link. The first one added is the outermost.

pPolicy
The policy. Not owned.
false when pPolicy is null or kMaxLinks are already there.
function

Execute

#
EStatus Execute( const SOperation & Op ) const noexcept

Runs the operation through the chain.

Op
The operation.
The status of the chain.
function

Count

#
std::size_t Count() const noexcept

Number of links.

policy.hpp

#include <ethereal/cpp/resilience/policy.hpp>

Shared parts of the Resilience module.

Status codes, the clock, the per thread random generator, the operation reference and the statistics snapshot used by every policy.

Policies wrap every outbound call, and over 99 percent of those calls succeed. On the success path the wrapper must be nearly invisible: no allocations on any path, composition resolved at compile time, and the closed breaker check reduced to one relaxed atomic load and one compare.

The module has its own clock. Ethereal::Time::IClock is better, but section 2 of the conventions forbids including another module's header for functionality, and the spec promises "Depends on: nothing at link time". The cost is ten duplicated lines, and users of the policies do not pull the Time module.

enum

EStatus

Ethereal::Resilience#
C++
enum class   EStatus : ETL_UINT8
{
    /// @brief  Succeeded.
    eOk = 0,

    /// @brief  Failed, and the failure came from the operation.
    eFailed,

    /// @brief  Did not finish in time.
    eTimeout,

    /// @brief  Never started: no free slot. See @ref CBulkhead.
    eRejected,

    /// @brief  Never started: the breaker is open. See @ref CCircuitBreaker.
    eOpen,

    /// @brief  Never started: no credit left. See @ref CRateLimiter.
    eThrottled,

    /// @brief  Attempts were left, but the time budget ran out.
    eBudgetExhausted,

    /// @brief  The caller gave up.
    eCancelled
};

How an operation, or the policy that wrapped it, ended.

function

StatusName

Ethereal::Resilience#
const ETL_CHAR * StatusName( EStatus eStatus ) noexcept;

Name of a status, for messages.

eStatus
The status.
A static string. Never null.
class

IClock

Ethereal::Resilience#
class IClock
destructor

~IClock

#
virtual ~IClock() = default;

Destructor.

function

NowNs

#
virtual ETL_UINT64 NowNs() const noexcept = 0;

Nanoseconds since an arbitrary point. Only has to move forward.

function

SystemClock

Ethereal::Resilience#
IClock & SystemClock() noexcept;
class

CManualClock

Ethereal::Resilience#

A clock that only moves when told to. For tests.

class CManualClock final : public IClock
function

NowNs

#
ETL_UINT64 NowNs() const noexcept override

Current time, in nanoseconds.

function

Advance

#
void Advance( const ETL_UINT64 uNs ) noexcept

Moves the clock forward. Stops at the largest 64 bit value.

A clock that wrapped around would go back in time, and a policy would take an open duration as already over.

uNs
Nanoseconds to add.
function

AdvanceMs

#
void AdvanceMs( const ETL_UINT64 uMs ) noexcept

Moves the clock forward.

uMs
Milliseconds to add.
function

NextRandom

Ethereal::Resilience#
ETL_UINT64 NextRandom() noexcept;

Next number of the per thread generator.

xoshiro256++, seeded once per thread. Small, fast and lock free. rand is global and of poor quality. std::mt19937 takes two kilobytes and fills the cache. A shared generator would put a lock on the jitter path, which is where everyone retrying at the same time goes through.

Jitter is required by the spec and on by default. Without it, a hundred clients that failed together wait the same backoff and hit the service together again. Backoff without jitter synchronizes the load instead of spreading it.

function

RandomBelow

Ethereal::Resilience#
ETL_UINT64 RandomBelow( ETL_UINT64 uLimit ) noexcept;

A random number in [0, uLimit). No division on the hot path.

uLimit
Exclusive upper bound. Zero returns zero.
The number.
class

SOperation

Ethereal::Resilience#

What the policies wrap: a call that returns a status.

class SOperation final

A pair of pointers, context and function, that owns nothing and does not outlive the expression where it is built. This is the spec's function_ref. A std::function here would cost one allocation per call.

alias

EStatus

#
using Fn = EStatus ( * )( void * ) noexcept;

Function called with the context.

constructor

SOperation

#
SOperation( void * const pCtx, const Fn pFn ) noexcept : m_pCtx( pCtx ), m_pFn( pFn )

Builds from a context and a function.

pCtx
Context passed to the function.
pFn
The function.
function

IsValid

#
bool IsValid() const noexcept

true when a function is set.

macro

ETL_RES_COUNT

#
#define ETL_RES_COUNT( x ) ( ( void ) 0 )

Does not count.

macro

ETL_RES_COUNT

#
#define ETL_RES_COUNT( x ) ( x )

Counts.

struct

SPolicyStats

Ethereal::Resilience#
C++
struct   SPolicyStats   final
{
    /// @brief  Calls that entered the policy.
    ETL_UINT64    uAttempts = 0;

    /// @brief  Calls that ended in eOk.
    ETL_UINT64    uSuccesses = 0;

    /// @brief  Calls that failed.
    ETL_UINT64    uFailures = 0;

    /// @brief  Retries made.
    ETL_UINT64    uRetries = 0;

    /// @brief  Calls rejected before running.
    ETL_UINT64    uRejections = 0;

    /// @brief  Breaker state changes.
    ETL_UINT64    uTransitions = 0;

    /// @brief  Total time spent waiting, in nanoseconds.
    ETL_UINT64    uWaitedNs = 0;
};

The counters of a policy, read at once.

Read with relaxed atomic loads and no lock. Fields may come from slightly different instants. That is preferred over stopping the hot path to read them together.

retry.hpp

#include <ethereal/cpp/resilience/retry.hpp>

Retry policy of the Resilience module.

Runs an operation again after a failure, with backoff and jitter.

No default retries. Retrying an operation that is not idempotent applies its effect twice ("transfer one hundred" transfers two hundred), and the likeliest case is exactly that: the request arrived, was done, and the response was lost. A caller that wants retries has to declare the operation idempotent in SRetryPolicy::bIdempotent.

Jitter is on by default. See the note on NextRandom in policy.hpp.

The total budget is checked before sleeping ("TotalBudget is checked before sleeping, so the policy never sleeps past the budget"). Otherwise a policy with a one second budget and a two second backoff would sleep two seconds and report the budget exhausted one second late.

enum

EBackoff

Ethereal::Resilience#
C++
enum class   EBackoff : ETL_UINT8
{
    /// @brief  No wait. For cheap local operations.
    eNone = 0,

    /// @brief  Always the same time.
    eConstant,

    /// @brief  Base, 2×base, 3×base...
    eLinear,

    /// @brief  Base, 2×base, 4×base... The default.
    eExponential,

    /// @brief  The next delay is drawn between the base and three times the previous one.
    ///
    /// @details  Best for many clients retrying at once. Each one keeps its own
    ///            pace and the delays do not line up again, as they do with
    ///            exponential plus jitter, where the ceiling is still shared.
    eDecorrelated
};

How the time between attempts grows.

enum

EJitter

Ethereal::Resilience#
C++
enum class   EJitter : ETL_UINT8
{
    /// @brief  None. Read the note on NextRandom before choosing this.
    eNone = 0,

    /// @brief  Drawn between zero and the computed delay. The default.
    eFull,

    /// @brief  Half fixed, half random.
    eEqual
};

How much of the computed delay is random.

alias

bool

Ethereal::Resilience#
using RetryablePredicate = bool ( * )( void * pCtx, EStatus eStatus );

Tells whether a result is worth retrying.

alias

void

Ethereal::Resilience#
using RetryCallback = void ( * )( void * pCtx, ETL_UINT32 uAttempt, ETL_UINT64 uDelayNs, EStatus eStatus );

Called before each wait, with the attempt number, the delay and the last status.

struct

SRetryPolicy

Ethereal::Resilience#
C++
struct   SRetryPolicy   final
{
    /// @brief  Total attempts, not retries. One means no retry.
    ETL_UINT32            uMaxAttempts = 1u;

    /// @brief  How the delay grows.
    EBackoff            eBackoff = EBackoff::eExponential;

    /// @brief  How much of the delay is random.
    EJitter                eJitter = EJitter::eFull;

    /// @brief  Base delay, in milliseconds.
    ETL_UINT64            uBaseDelayMs = 50u;

    /// @brief  Maximum delay, in milliseconds.
    ETL_UINT64            uMaxDelayMs = 5000u;

    /// @brief  Time limit for all attempts together. Zero means no limit.
    ETL_UINT64            uTotalBudgetMs = 0u;

    /// @brief  The operation can run twice without harm.
    ///
    /// @details  While false, @ref CRetry::Execute runs the operation once and
    ///            returns its status, whatever uMaxAttempts says. A field that
    ///            has to be set to true makes the caller state it, and leaves
    ///            the statement in the code.
    bool                bIdempotent = false;

    /// @brief  Decides what is retried. Null uses @ref DefaultRetryable.
    RetryablePredicate    pIsRetryable = nullptr;

    /// @brief  Context passed to pIsRetryable.
    void *                pRetryableCtx = nullptr;

    /// @brief  Called before each wait. May be null.
    RetryCallback        pOnRetry = nullptr;

    /// @brief  Context passed to pOnRetry.
    void *                pOnRetryCtx = nullptr;
};

Retry configuration.

function

DefaultRetryable

Ethereal::Resilience#
bool DefaultRetryable( void * pCtx, EStatus eStatus );

Default predicate: retries what may have come from the path, not from the request.

Retries failure, timeout, rejection and throttling. An open breaker is not retried, it is open so callers stop insisting. A cancellation is not retried either, the caller gave up.

pCtx
Unused.
eStatus
Status of the last attempt.
true when the status is worth retrying.
class

CRetry

Ethereal::Resilience#

Retries what can be retried.

class CRetry final
No shared state: the state of a retry lives on the caller's stack. One object serves many threads.
constructor

CRetry

#
explicit CRetry( const SRetryPolicy & Policy = SRetryPolicy(), IClock & Clock = SystemClock() ) noexcept : m_Policy( Policy ), m_pClock( &Clock )

Builds the policy.

Policy
Retry configuration.
Clock
Clock used for the total budget.
function

Execute

#
template< typename F > EStatus Execute( F && Op ) noexcept

Runs the operation and retries what can be retried.

A template so the chain can be inlined. See the same note on CCircuitBreaker::Execute.

Op
Callable returning EStatus.
eOk, the status of the last attempt, or eBudgetExhausted.
function

SleepNs

#
static void SleepNs( const ETL_UINT64 uNs ) noexcept;

Sleeps. Out of the template so the header does not pull <thread>.

uNs
Nanoseconds to sleep.
function

DelayForAttemptNs

#
ETL_UINT64 DelayForAttemptNs( const ETL_UINT32 uAttempt, const ETL_UINT64 uPreviousNs ) const noexcept;

Delay before the attempt after uAttempt, jitter included.

Public because a distribution test needs to see it, and so does a caller that wants to do the wait its own way.

uAttempt
Zero based index of the attempt that failed.
uPreviousNs
Previous delay. Used by eDecorrelated.
The delay, in nanoseconds.
function

Stats

#
SPolicyStats Stats() const noexcept;

Counters of the policy.

function

Policy

#
const SRetryPolicy & Policy() const noexcept

The configuration.