The Sparta Modeling Framework
Loading...
Searching...
No Matches
SpartaExpBackoff.hpp
1// <SpartaExpBackoff> -*- C++ -*-
2
7#pragma once
8
9
10namespace sparta {
11
15 namespace exp_backoff {
16
20typedef uint32_t counter_t;
21
25#define SPARTA_EXPBO_CONCAT_ARG2(x,y,z) x##_##y##_##z
26
32#define SPARTA_EXPBO_CONCAT_ARG(x,y,z) SPARTA_EXPBO_CONCAT_ARG2(x,y,z)
33
52#define SPARTA_EXPONENTIAL_BACKOFF(mult, action) \
53 static sparta::exp_backoff::counter_t SPARTA_EXPBO_CONCAT_ARG(_count,__LINE__,mult) = 0; \
54 static sparta::exp_backoff::counter_t SPARTA_EXPBO_CONCAT_ARG(_next,__LINE__,mult) = 1; \
55 SPARTA_EXPBO_CONCAT_ARG(_count,__LINE__,mult) ++; \
56 if(SPARTA_EXPBO_CONCAT_ARG(_count,__LINE__,mult) >= SPARTA_EXPBO_CONCAT_ARG(_next,__LINE__,mult)){ \
57 const sparta::exp_backoff::counter_t& SPARTA_EXPONENTIAL_BACKOFF_COUNT = SPARTA_EXPBO_CONCAT_ARG(_count,__LINE__,mult); \
58 (void) SPARTA_EXPONENTIAL_BACKOFF_COUNT; \
59 action; \
60 SPARTA_EXPBO_CONCAT_ARG(_next,__LINE__,mult) *= mult; \
61 }
62
63 } // namespace exp_backoff
64} // namespace sparta
65
uint32_t counter_t
Type use for exponential backoff counters.
Macros for handling exponential backoff.