| 82 | } |
| 83 | |
| 84 | bool Pop(T* result) { |
| 85 | std::unique_lock<std::mutex> unique_lock(mtx_); |
| 86 | if (!WaitUntilCanPopOrClosed(unique_lock)) return false; |
| 87 | |
| 88 | *result = std::move(buffer_[left_]); |
| 89 | |
| 90 | left_ = (left_ + 1) % capacity_; |
| 91 | buffer_size_--; |
| 92 | |
| 93 | not_full_.notify_one(); |
| 94 | |
| 95 | return true; |
| 96 | } |
| 97 | |
| 98 | void Close() { |
| 99 | std::unique_lock<std::mutex> unique_lock(mtx_); |