| 58 | bool HostStream::WorkAvailable() { return !work_queue_.empty(); } |
| 59 | |
| 60 | void HostStream::WorkLoop() { |
| 61 | // Set denormal and rounding behavior to match the default TF ThreadPool |
| 62 | // behavior. |
| 63 | // TODO(phawkins, jlebar): it's not clear this is the best place to set this. |
| 64 | tensorflow::port::ScopedFlushDenormal flush; |
| 65 | tensorflow::port::ScopedSetRound round(FE_TONEAREST); |
| 66 | while (true) { |
| 67 | std::function<void()> fn; |
| 68 | { |
| 69 | absl::MutexLock lock(&mu_); |
| 70 | mu_.Await(absl::Condition(this, &HostStream::WorkAvailable)); |
| 71 | fn = std::move(work_queue_.front()); |
| 72 | work_queue_.pop(); |
| 73 | } |
| 74 | if (!fn) { |
| 75 | return; |
| 76 | } |
| 77 | fn(); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | void HostStream::BlockUntilDone() { |
| 82 | absl::Notification done; |