| 238 | } |
| 239 | |
| 240 | void QueueBase::Close(OpKernelContext* ctx, bool cancel_pending_enqueues, |
| 241 | DoneCallback callback) { |
| 242 | if (cancel_pending_enqueues) { |
| 243 | CloseAndCancel(); |
| 244 | callback(); |
| 245 | } else { |
| 246 | { |
| 247 | mutex_lock lock(mu_); |
| 248 | enqueue_attempts_.emplace_back( |
| 249 | 0, callback, ctx, nullptr, CancellationManager::kInvalidToken, |
| 250 | [this](Attempt* attempt) EXCLUSIVE_LOCKS_REQUIRED(mu_) { |
| 251 | if (closed_) { |
| 252 | attempt->context->SetStatus( |
| 253 | errors::Cancelled("Queue '", name_, "' is already closed.")); |
| 254 | } else { |
| 255 | closed_ = true; |
| 256 | } |
| 257 | return kComplete; |
| 258 | }); |
| 259 | } |
| 260 | FlushUnlocked(); |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | bool QueueBase::TryAttemptLocked(Action action, |
| 265 | std::vector<CleanUp>* clean_up) { |