| 153 | // https://en.cppreference.com/w/cpp/utility/forward for details. |
| 154 | template<typename U> |
| 155 | QueueStatus Put(U&& val) { |
| 156 | MutexLock l(lock_); |
| 157 | if (PREDICT_FALSE(shutdown_)) { |
| 158 | return QUEUE_SHUTDOWN; |
| 159 | } |
| 160 | if (size_ >= max_size_) { |
| 161 | return QUEUE_FULL; |
| 162 | } |
| 163 | increment_size_unlocked(val); |
| 164 | queue_.emplace_back(std::forward<U>(val)); |
| 165 | l.Unlock(); |
| 166 | not_empty_.Signal(); |
| 167 | return QUEUE_SUCCESS; |
| 168 | } |
| 169 | |
| 170 | // Puts an element onto the queue; if the queue is full, blocks until space |
| 171 | // becomes available, or until the deadline passes. |