Evicts waiting tensors and callbacks that have exceeded their deadline.
| 1003 | private: |
| 1004 | // Evicts waiting tensors and callbacks that have exceeded their deadline. |
| 1005 | void EnforceTimeout() { |
| 1006 | const uint64 now = Env::Default()->NowMicros(); |
| 1007 | std::vector<WaitingCallback> evicted_callbacks; |
| 1008 | |
| 1009 | { |
| 1010 | mutex_lock ml(mu_); |
| 1011 | |
| 1012 | for (auto it = waiting_tensors_.begin(); it != waiting_tensors_.end();) { |
| 1013 | const WaitingTensor& waiting_tensor = it->second; |
| 1014 | if (waiting_tensor.deadline_micros < now) { |
| 1015 | it = waiting_tensors_.erase(it); |
| 1016 | } else { |
| 1017 | ++it; |
| 1018 | } |
| 1019 | } |
| 1020 | |
| 1021 | for (auto it = waiting_callbacks_.begin(); |
| 1022 | it != waiting_callbacks_.end();) { |
| 1023 | const WaitingCallback& waiting_callback = it->second; |
| 1024 | if (waiting_callback.deadline_micros < now) { |
| 1025 | evicted_callbacks.push_back(waiting_callback); |
| 1026 | it = waiting_callbacks_.erase(it); |
| 1027 | } else { |
| 1028 | ++it; |
| 1029 | } |
| 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | for (const WaitingCallback& evicted_callback : evicted_callbacks) { |
| 1034 | evicted_callback.context->CtxFailureWithWarning(errors::DeadlineExceeded( |
| 1035 | "Batched data did not arrive within timeout window.")); |
| 1036 | evicted_callback.done(); |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | struct WaitingTensor { |
| 1041 | uint64 deadline_micros; |