| 125 | } |
| 126 | |
| 127 | void RandomShuffleQueue::TryEnqueue(const Tuple& tuple, OpKernelContext* ctx, |
| 128 | DoneCallback callback) { |
| 129 | CancellationManager* cm = ctx->cancellation_manager(); |
| 130 | CancellationToken token = cm->get_cancellation_token(); |
| 131 | bool already_cancelled; |
| 132 | { |
| 133 | mutex_lock l(mu_); |
| 134 | already_cancelled = !cm->RegisterCallback( |
| 135 | token, [this, cm, token]() { Cancel(kEnqueue, cm, token); }); |
| 136 | if (!already_cancelled) { |
| 137 | enqueue_attempts_.emplace_back( |
| 138 | 1, callback, ctx, cm, token, |
| 139 | [tuple, this](Attempt* attempt) EXCLUSIVE_LOCKS_REQUIRED(mu_) { |
| 140 | if (closed_) { |
| 141 | attempt->context->SetStatus(errors::Cancelled( |
| 142 | "RandomShuffleQueue '", name_, "' is closed.")); |
| 143 | return kComplete; |
| 144 | } |
| 145 | if (queues_[0].size() < static_cast<size_t>(capacity_)) { |
| 146 | for (int i = 0; i < num_components(); ++i) { |
| 147 | queues_[i].push_back(PersistentTensor(tuple[i])); |
| 148 | } |
| 149 | return kComplete; |
| 150 | } else { |
| 151 | return kNoProgress; |
| 152 | } |
| 153 | }); |
| 154 | } |
| 155 | } |
| 156 | if (!already_cancelled) { |
| 157 | FlushUnlocked(); |
| 158 | } else { |
| 159 | ctx->SetStatus(errors::Cancelled("Enqueue operation was cancelled")); |
| 160 | callback(); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | /* static */ |
| 165 | Status RandomShuffleQueue::GetElementComponentFromBatch( |
nothing calls this directly
no test coverage detected