| 196 | } |
| 197 | |
| 198 | bool ExecuteWithTimeout(std::function<void()> fn, const int64 timeout_in_ms, |
| 199 | thread::ThreadPool* const thread_pool) { |
| 200 | if (timeout_in_ms <= 0) { |
| 201 | fn(); |
| 202 | return true; |
| 203 | } |
| 204 | auto done = std::make_shared<Notification>(); |
| 205 | thread_pool->Schedule([done, fn]() { |
| 206 | fn(); |
| 207 | done->Notify(); |
| 208 | }); |
| 209 | const bool notified = |
| 210 | WaitForNotificationWithTimeout(done.get(), timeout_in_ms * 1000); |
| 211 | return notified; |
| 212 | } |
| 213 | |
| 214 | string AsControlDependency(const NodeDef& node) { |
| 215 | return absl::StrCat("^", node.name()); |