| 219 | } |
| 220 | |
| 221 | Future<> WaitForNextReleasedBatch() { |
| 222 | std::lock_guard lg(mutex_); |
| 223 | if (current_waiter_.is_valid()) { |
| 224 | return current_waiter_; |
| 225 | } |
| 226 | Future<> fut; |
| 227 | if (num_allowed_batches_ < 0 || num_released_batches_ < num_allowed_batches_) { |
| 228 | num_released_batches_++; |
| 229 | return Future<>::MakeFinished(); |
| 230 | } |
| 231 | |
| 232 | current_waiter_ = Future<>::Make(); |
| 233 | return current_waiter_; |
| 234 | } |
| 235 | |
| 236 | private: |
| 237 | void NotifyAll() { |