Change timer() to now() to preserve determinism

This commit is contained in:
Chaoguang Lin 2020-12-08 16:44:39 -08:00
parent 90f56d0e84
commit f8ed207ee4
1 changed files with 2 additions and 2 deletions

View File

@ -38,7 +38,7 @@ public:
class SpeedLimit : public IRateControl, ReferenceCounted<SpeedLimit> { class SpeedLimit : public IRateControl, ReferenceCounted<SpeedLimit> {
public: public:
SpeedLimit(int windowLimit, double windowSeconds) : m_limit(windowLimit), m_seconds(windowSeconds), m_last_update(0), m_budget(0) { SpeedLimit(int windowLimit, double windowSeconds) : m_limit(windowLimit), m_seconds(windowSeconds), m_last_update(0), m_budget(0) {
m_last_update = timer(); m_last_update = now();
} }
virtual ~SpeedLimit() {} virtual ~SpeedLimit() {}
@ -47,7 +47,7 @@ public:
virtual Future<Void> getAllowance(unsigned int n) { virtual Future<Void> getAllowance(unsigned int n) {
// Replenish budget based on time since last update // Replenish budget based on time since last update
double ts = timer(); double ts = now();
// returnUnused happens to do exactly what we want here // returnUnused happens to do exactly what we want here
returnUnused((ts - m_last_update) / m_seconds * m_limit); returnUnused((ts - m_last_update) / m_seconds * m_limit);
m_last_update = ts; m_last_update = ts;