20 U32 replenishInterval,
26 m_replenishInterval(replenishInterval),
27 m_maxTokens(maxTokens),
28 m_replenishRate(replenishRate),
29 m_tokens(startTokens),
36 U32 replenishInterval,
39 m_replenishInterval(replenishInterval),
40 m_maxTokens(maxTokens),
53 this->m_replenishInterval = replenishInterval;
61 this->m_maxTokens = maxTokens;
69 this->m_replenishRate = replenishRate;
75 if (this->m_tokens < this->m_maxTokens) {
76 this->m_tokens = this->m_maxTokens;
83 return this->m_replenishInterval;
89 return this->m_maxTokens;
95 return this->m_replenishRate;
101 return this->m_tokens;
110 if (this->m_replenishRate > 0) {
111 Fw::Time replenishInterval =
Fw::Time(this->m_replenishInterval / 1000000, this->m_replenishInterval % 1000000);
113 while (this->m_tokens < this->m_maxTokens && nextTime <= time) {
115 this->m_tokens +=
FW_MIN(this->m_replenishRate, this->m_maxTokens - this->m_tokens);
116 this->m_time = nextTime;
119 if (this->m_tokens >= this->m_maxTokens && this->m_time < time) {
125 if (this->m_tokens > 0) {
#define FW_MIN(a, b)
MIN macro.
PlatformAssertArgType FwAssertArgType
#define MAX_TOKEN_BUCKET_TOKENS
static Time add(const Time &a, const Time &b)
void setMaxTokens(U32 maxTokens)
TokenBucket(U32 replenishInterval, U32 maxTokens, U32 replenishRate, U32 startTokens, Fw::Time startTime)
void setReplenishRate(U32 replenishRate)
U32 getReplenishInterval() const
bool trigger(const Fw::Time time)
U32 getReplenishRate() const
void setReplenishInterval(U32 replenishInterval)