| 94 | } |
| 95 | |
| 96 | Status EagerExecutor::Add(std::unique_ptr<EagerNode> node) { |
| 97 | Status status; |
| 98 | |
| 99 | // If we are unable to add the node to the queue, we must call Abort. However, |
| 100 | // we want to do that outside of the scope of the lock since the Abort may |
| 101 | // try to call EagerExecutor::Add() |
| 102 | { |
| 103 | tensorflow::mutex_lock l(node_queue_mutex_); |
| 104 | if (state_ != ExecutorState::kActive) { |
| 105 | status = errors::FailedPrecondition( |
| 106 | "EagerExecutor accepts new EagerNodes to run only in Active state. " |
| 107 | "Current state is '", |
| 108 | StateStringLocked(), "'"); |
| 109 | } else { |
| 110 | DCHECK(thread_) << "EnableAsync should have been called before Add"; |
| 111 | status = status_; |
| 112 | if (status.ok()) { |
| 113 | node_queue_.push(std::move(node)); |
| 114 | |
| 115 | // If there were no previous nodes pending, wake the run thread to start |
| 116 | // processing requests again. |
| 117 | if (node_queue_.size() == 1) { |
| 118 | nodes_pending_.notify_all(); |
| 119 | } |
| 120 | |
| 121 | return Status::OK(); |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | // Node needs to be aborted since it was not added to the queue |
| 127 | node->Abort(status); |
| 128 | return status; |
| 129 | } |
| 130 | |
| 131 | tensorflow::Status EagerExecutor::WaitForAllPendingNodes() { |
| 132 | tensorflow::mutex_lock l(node_queue_mutex_); |
no test coverage detected