| 151 | } |
| 152 | |
| 153 | void XrtTfContext::QueueThread() { |
| 154 | auto should_flush_queue = [this]() { |
| 155 | mu_.AssertHeld(); // For annotalysis. |
| 156 | return enqueue_request_->queue_size() > options_.max_queue_size || |
| 157 | flush_requested_ || shutting_down_; |
| 158 | }; |
| 159 | while (true) { |
| 160 | auto request = absl::make_unique<eager::EnqueueRequest>(); |
| 161 | { |
| 162 | absl::MutexLock lock(&mu_); |
| 163 | // To keep the connection alive, make sure we send an EnqueueRequest |
| 164 | // regularly, currently every 5 seconds. |
| 165 | mu_.AwaitWithTimeout(absl::Condition(&should_flush_queue), |
| 166 | absl::Seconds(5)); |
| 167 | if (shutting_down_) break; |
| 168 | std::swap(request, enqueue_request_); |
| 169 | flush_requested_ = false; |
| 170 | } |
| 171 | |
| 172 | std::vector<OperationId> op_ids; |
| 173 | for (const auto& item : request->queue()) { |
| 174 | if (item.has_operation()) { |
| 175 | op_ids.push_back(item.operation().id()); |
| 176 | } |
| 177 | } |
| 178 | request->set_context_id(context_id_); |
| 179 | |
| 180 | VLOG(10) << "Enqueue:\n" << request->DebugString(); |
| 181 | eager::EnqueueResponse response; |
| 182 | Status status; |
| 183 | absl::Notification done; |
| 184 | eager_client_->EnqueueAsync(request.get(), &response, [&](Status s) { |
| 185 | status = s; |
| 186 | done.Notify(); |
| 187 | }); |
| 188 | |
| 189 | done.WaitForNotification(); |
| 190 | |
| 191 | VLOG(10) << "EnqueueResponse: " << status << "\n" << response.DebugString(); |
| 192 | { |
| 193 | absl::MutexLock lock(&mu_); |
| 194 | if (status.ok()) { |
| 195 | for (OperationId op_id : op_ids) { |
| 196 | DeleteOperation(op_id); |
| 197 | } |
| 198 | } else { |
| 199 | ReportError(op_ids, status); |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | void XrtTfContext::ReportError(absl::Span<const OperationId> op_ids, |
| 206 | Status status) { |
nothing calls this directly
no test coverage detected