| 136 | } |
| 137 | |
| 138 | Status IteratorResource::SetIteratorFromDataset(OpKernelContext* ctx, |
| 139 | DatasetBase* dataset) { |
| 140 | std::shared_ptr<State> new_state; |
| 141 | { |
| 142 | tf_shared_lock l(mu_); |
| 143 | new_state = std::make_shared<State>( |
| 144 | iterator_state_->flib_def, iterator_state_->pflr, iterator_state_->flr, |
| 145 | /*iterator=*/nullptr); |
| 146 | } |
| 147 | // Create new iterator. |
| 148 | std::unique_ptr<IteratorBase> iterator; |
| 149 | IteratorContext::Params params(ctx); |
| 150 | params.flr = new_state->flr; |
| 151 | params.function_handle_cache = new_state->function_handle_cache.get(); |
| 152 | params.resource_mgr = &new_state->resource_mgr; |
| 153 | params.thread_factory = unbounded_thread_pool_.get_thread_factory(); |
| 154 | params.thread_pool = &unbounded_thread_pool_; |
| 155 | params.cancellation_manager = &new_state->cancellation_manager; |
| 156 | std::function<void()> deregister_fn; |
| 157 | TF_RETURN_IF_ERROR(ConnectCancellationManagers(ctx->cancellation_manager(), |
| 158 | params.cancellation_manager, |
| 159 | &deregister_fn)); |
| 160 | { |
| 161 | auto cleanup = gtl::MakeCleanup(std::move(deregister_fn)); |
| 162 | TF_RETURN_IF_ERROR(dataset->MakeIterator(IteratorContext(std::move(params)), |
| 163 | "Iterator", &iterator)); |
| 164 | TF_RETURN_IF_ERROR( |
| 165 | VerifyTypesMatch(output_dtypes_, iterator->output_dtypes())); |
| 166 | TF_RETURN_IF_ERROR( |
| 167 | VerifyShapesCompatible(output_shapes_, iterator->output_shapes())); |
| 168 | std::swap(new_state->iterator, iterator); |
| 169 | } |
| 170 | |
| 171 | mutex_lock l(mu_); |
| 172 | std::swap(iterator_state_, new_state); |
| 173 | return Status::OK(); |
| 174 | } |
| 175 | |
| 176 | namespace { |
| 177 |
no test coverage detected