Gets an element from the queue; if the queue is empty, blocks until the queue becomes non-empty, or until the deadline passes. If the queue has been shut down but there are still elements in the queue, it returns those elements as if the queue were not yet shut down. Returns: - OK if successful - TimedOut if the deadline passed - Aborted if the queue shut down
| 83 | // - TimedOut if the deadline passed |
| 84 | // - Aborted if the queue shut down |
| 85 | Status BlockingGet(T* out, MonoTime deadline = {}) { |
| 86 | MutexLock l(lock_); |
| 87 | while (true) { |
| 88 | if (!queue_.empty()) { |
| 89 | *out = std::move(queue_.front()); |
| 90 | queue_.pop_front(); |
| 91 | decrement_size_unlocked(*out); |
| 92 | l.Unlock(); |
| 93 | not_full_.Signal(); |
| 94 | return Status::OK(); |
| 95 | } |
| 96 | if (PREDICT_FALSE(shutdown_)) { |
| 97 | return Status::Aborted(""); |
| 98 | } |
| 99 | if (!deadline.Initialized()) { |
| 100 | not_empty_.Wait(); |
| 101 | } else if (PREDICT_FALSE(!not_empty_.WaitUntil(deadline))) { |
| 102 | return Status::TimedOut(""); |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | // Get all elements from the queue and append them to a vector. |
| 108 | // |