summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Schodet2016-09-07 15:29:51 +0200
committerNicolas Schodet2019-10-09 23:05:51 +0200
commit01585a368762caa2e5acb077f48f477339f7ed67 (patch)
treea7c7444a6868290dba679a7ed88ce19c788768ec
parentf7d0eea6fdf646241265d58bd7b35643a68a47cb (diff)
ucoo/utils: add RateLimit::reset
-rw-r--r--ucoo/utils/rate_limit.hh2
-rw-r--r--ucoo/utils/rate_limit.tcc7
2 files changed, 9 insertions, 0 deletions
diff --git a/ucoo/utils/rate_limit.hh b/ucoo/utils/rate_limit.hh
index c902257..0020ac7 100644
--- a/ucoo/utils/rate_limit.hh
+++ b/ucoo/utils/rate_limit.hh
@@ -45,6 +45,8 @@ class RateLimit
/// Refresh timestamp to avoid overflow, must be called periodically when
/// permission is not requested often enough.
void refresh ();
+ /// Reset as if permission was allowed.
+ void reset ();
private:
/// Associated timer.
const Timer &timer_;
diff --git a/ucoo/utils/rate_limit.tcc b/ucoo/utils/rate_limit.tcc
index 938c20f..9333cd1 100644
--- a/ucoo/utils/rate_limit.tcc
+++ b/ucoo/utils/rate_limit.tcc
@@ -77,6 +77,13 @@ RateLimit<Timer>::refresh ()
next_ = val;
}
+template<typename Timer>
+void
+RateLimit<Timer>::reset ()
+{
+ next_ = timer_.get_value () + interval_;
+}
+
} // namespace ucoo
#endif // ucoo_utils_rate_limit_tcc