21 bool waiting(std::int64_t now_ms)
const {
return now_ms < until_ms_.load(std::memory_order_relaxed); }
25 const int n = refusals_.fetch_add(1, std::memory_order_relaxed);
26 const std::int64_t delay = std::min(
kFirstMs << std::min(n, 5),
kMaxMs);
27 until_ms_.store(now_ms + delay, std::memory_order_relaxed);
31 void accepted() { refusals_.store(0, std::memory_order_relaxed); }
37 std::atomic<std::int64_t> until_ms_{0};
38 std::atomic<int> refusals_{0};
static constexpr std::int64_t kMaxMs
void refused(std::int64_t now_ms)
The device refused (not enough free memory, or allocation failed): wait, twice as long as last time.
bool waiting(std::int64_t now_ms) const
True while a refusal is recent enough that the device should not be asked.
std::int64_t next_delay_ms() const
Delay a refusal at this point would set (for tests and logs).
static constexpr std::int64_t kFirstMs
void accepted()
The device took work again: the next refusal starts from the first delay.