| 184 | // https://en.cppreference.com/w/cpp/utility/forward for details. |
| 185 | template<typename U> |
| 186 | Status BlockingPut(U&& val, MonoTime deadline = {}) { |
| 187 | if (PREDICT_FALSE(deadline.Initialized() && MonoTime::Now() > deadline)) { |
| 188 | return Status::TimedOut(""); |
| 189 | } |
| 190 | MutexLock l(lock_); |
| 191 | while (true) { |
| 192 | if (PREDICT_FALSE(shutdown_)) { |
| 193 | return Status::Aborted(""); |
| 194 | } |
| 195 | if (size_ < max_size_) { |
| 196 | increment_size_unlocked(val); |
| 197 | queue_.emplace_back(std::forward<U>(val)); |
| 198 | l.Unlock(); |
| 199 | not_empty_.Signal(); |
| 200 | return Status::OK(); |
| 201 | } |
| 202 | if (!deadline.Initialized()) { |
| 203 | not_full_.Wait(); |
| 204 | } else if (PREDICT_FALSE(!not_full_.WaitUntil(deadline))) { |
| 205 | return Status::TimedOut(""); |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | // Shuts down the queue. |
| 211 | // |