mirror of
https://github.com/Zygo/bees.git
synced 2025-06-15 17:26:15 +02:00
time: add more methods to support dynamic rate throttling
* Allow RateLimiter to change rate after construction. * Check range of rate argument in constructor. * Atomic increment for RateEstimator. Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
@ -34,7 +34,7 @@ namespace crucible {
|
||||
double m_rate;
|
||||
double m_burst;
|
||||
double m_tokens = 0.0;
|
||||
mutex m_mutex;
|
||||
mutable mutex m_mutex;
|
||||
|
||||
void update_tokens();
|
||||
RateLimiter() = delete;
|
||||
@ -45,6 +45,8 @@ namespace crucible {
|
||||
double sleep_time(double cost = 1.0);
|
||||
bool is_ready();
|
||||
void borrow(double cost = 1.0);
|
||||
void rate(double new_rate);
|
||||
double rate() const;
|
||||
};
|
||||
|
||||
class RateEstimator {
|
||||
@ -88,6 +90,9 @@ namespace crucible {
|
||||
// Read count
|
||||
uint64_t count() const;
|
||||
|
||||
/// Increment count (like update(count() + more), but atomic)
|
||||
void increment(uint64_t more = 1);
|
||||
|
||||
// Convert counts to chrono types
|
||||
chrono::high_resolution_clock::time_point time_point(uint64_t absolute_count) const;
|
||||
chrono::duration<double> duration(uint64_t relative_count) const;
|
||||
|
Reference in New Issue
Block a user