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