MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / TryDequeue

Method TryDequeue

tensorflow/core/kernels/priority_queue.cc:197–236  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

195}
196
197void PriorityQueue::TryDequeue(OpKernelContext* ctx,
198 CallbackWithTuple callback) {
199 CancellationManager* cm = ctx->cancellation_manager();
200 CancellationToken token = cm->get_cancellation_token();
201 bool already_cancelled;
202 {
203 mutex_lock l(mu_);
204 already_cancelled = !cm->RegisterCallback(
205 token, [this, cm, token]() { Cancel(kDequeue, cm, token); });
206 if (!already_cancelled) {
207 // TODO(josh11b): This makes two copies of callback, avoid this if possible.
208 dequeue_attempts_.emplace_back(
209 1, [callback]() { callback(Tuple()); }, ctx, cm, token,
210 [callback, this](Attempt* attempt) EXCLUSIVE_LOCKS_REQUIRED(mu_) {
211 const int32 s = queues_[0].size();
212 if (closed_ && s == 0) {
213 attempt->context->SetStatus(errors::OutOfRange(
214 "PriorityQueue '", name_, "' is closed and has ",
215 "insufficient elements (requested ", 1, ", current size ", s,
216 ")"));
217 return kComplete;
218 }
219 if (s > 0) {
220 Tuple tuple;
221 DequeueLocked(attempt->context, &tuple);
222 attempt->done_callback = [callback, tuple]() { callback(tuple); };
223 return kComplete;
224 } else {
225 return kNoProgress;
226 }
227 });
228 }
229 }
230 if (!already_cancelled) {
231 FlushUnlocked();
232 } else {
233 ctx->SetStatus(errors::Cancelled("Dequeue operation was cancelled"));
234 callback(Tuple());
235 }
236}
237
238void PriorityQueue::TryDequeueMany(int num_elements, OpKernelContext* ctx,
239 bool allow_small_batch,

Callers

nothing calls this directly

Calls 10

callbackFunction · 0.85
CancelledFunction · 0.85
TupleFunction · 0.50
EXCLUSIVE_LOCKS_REQUIREDFunction · 0.50
cancellation_managerMethod · 0.45
RegisterCallbackMethod · 0.45
emplace_backMethod · 0.45
sizeMethod · 0.45
SetStatusMethod · 0.45

Tested by

no test coverage detected