MCPcopy Create free account
hub / github.com/apache/impala / BlockingPutWithTimeout

Method BlockingPutWithTimeout

be/src/util/blocking-queue.h:173–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

171 /// inserted into the queue.
172 template <typename V>
173 bool BlockingPutWithTimeout(V&& val, int64_t timeout_micros) {
174 MonotonicStopWatch timer;
175 int64_t val_bytes = ElemBytesFn()(val);
176 DCHECK_GE(val_bytes, 0);
177 std::unique_lock<std::mutex> write_lock(put_lock_);
178 timespec abs_time;
179 TimeFromNowMicros(timeout_micros, &abs_time);
180 bool notified = true;
181 while (!HasCapacityInternal(write_lock, val_bytes) && !shutdown_ && notified) {
182 if (put_wait_timer_ != nullptr) timer.Start();
183 // Wait until we're notified or until the timeout expires.
184 notified = put_cv_.WaitUntil(write_lock, abs_time);
185 if (put_wait_timer_ != nullptr) timer.Stop();
186 }
187 if (put_wait_timer_ != nullptr) put_wait_timer_->Add(timer.ElapsedTime());
188 // If the list is still full or if the the queue has been shut down, return false.
189 // NOTE: We don't check 'notified' here as it appears that pthread condition variables
190 // have a weird behavior in which they can return ETIMEDOUT from timed_wait even if
191 // another thread did in fact signal
192 if (!HasCapacityInternal(write_lock, val_bytes)) return false;
193 DCHECK_LT(put_list_.size(), max_elements_);
194 put_bytes_enqueued_ += val_bytes;
195 Put(std::forward<V>(val));
196 write_lock.unlock();
197 get_cv_.NotifyOne();
198 return true;
199 }
200
201 /// Shut down the queue. Wakes up all threads waiting on BlockingGet or BlockingPut.
202 void Shutdown() {

Callers 3

AddBatchWithTimeoutMethod · 0.80
OfferMethod · 0.80
TESTFunction · 0.80

Calls 9

TimeFromNowMicrosFunction · 0.85
NotifyOneMethod · 0.80
StartMethod · 0.45
WaitUntilMethod · 0.45
StopMethod · 0.45
AddMethod · 0.45
ElapsedTimeMethod · 0.45
sizeMethod · 0.45
unlockMethod · 0.45

Tested by 1

TESTFunction · 0.64