| 46 | } |
| 47 | |
| 48 | std::optional<Future<>> TryAcquire(int amt) override { |
| 49 | std::lock_guard<std::mutex> lk(mutex_); |
| 50 | if (backoff_.is_valid()) { |
| 51 | return backoff_; |
| 52 | } |
| 53 | if (amt <= available_cost_) { |
| 54 | available_cost_ -= amt; |
| 55 | return std::nullopt; |
| 56 | } |
| 57 | backoff_ = Future<>::Make(); |
| 58 | return backoff_; |
| 59 | } |
| 60 | |
| 61 | void Release(int amt) override { |
| 62 | std::unique_lock lk(mutex_); |
no test coverage detected