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

Method TryDequeue

tensorflow/core/kernels/fifo_queue.cc:155–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153}
154
155void FIFOQueue::TryDequeue(OpKernelContext* ctx, CallbackWithTuple callback) {
156 CancellationManager* cm = ctx->cancellation_manager();
157 CancellationToken token = cm->get_cancellation_token();
158 bool already_cancelled;
159 {
160 mutex_lock l(mu_);
161 already_cancelled = !cm->RegisterCallback(
162 token, [this, cm, token]() { Cancel(kDequeue, cm, token); });
163 if (!already_cancelled) {
164 // TODO(josh11b): This makes two copies of callback, avoid this if possible.
165 dequeue_attempts_.emplace_back(
166 1, [callback]() { callback(Tuple()); }, ctx, cm, token,
167 [callback, this](Attempt* attempt) EXCLUSIVE_LOCKS_REQUIRED(mu_) {
168 const int64 queue_size = queues_[0].size();
169 if (closed_ && queue_size == 0) {
170 attempt->context->SetStatus(errors::OutOfRange(
171 "FIFOQueue '", name_, "' is closed and has ",
172 "insufficient elements (requested ", 1, ", current size ",
173 queue_size, ")"));
174 return kComplete;
175 }
176 if (queue_size > 0) {
177 Tuple tuple;
178 DequeueLocked(attempt->context, &tuple);
179 attempt->done_callback = [callback, tuple]() { callback(tuple); };
180 return kComplete;
181 } else {
182 return kNoProgress;
183 }
184 });
185 }
186 }
187 if (!already_cancelled) {
188 FlushUnlocked();
189 } else {
190 ctx->SetStatus(errors::Cancelled("Dequeue operation was cancelled"));
191 callback(Tuple());
192 }
193}
194
195void FIFOQueue::TryDequeueMany(int num_elements, OpKernelContext* ctx,
196 bool allow_small_batch,

Callers 2

GetNextWorkLockedMethod · 0.45
ComputeAsyncMethod · 0.45

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