A worker thread that runs a sequence of closures. Equivalent to a thread pool of size 1.
| 29 | // A worker thread that runs a sequence of closures. Equivalent to a thread |
| 30 | // pool of size 1. |
| 31 | class WorkerThread { |
| 32 | public: |
| 33 | // 'name' is a name for the thread for debugging purposes. |
| 34 | WorkerThread(tensorflow::Env* env, const std::string& name); |
| 35 | |
| 36 | // Blocks until all enqueued closures have completed. |
| 37 | ~WorkerThread(); |
| 38 | |
| 39 | // Adds 'fn' to the queue of closures to be executed by the worker thread. |
| 40 | void Schedule(std::function<void()> fn); |
| 41 | |
| 42 | private: |
| 43 | bool WorkAvailable() TF_EXCLUSIVE_LOCKS_REQUIRED(mu_); |
| 44 | void WorkLoop(); |
| 45 | |
| 46 | absl::Mutex mu_; |
| 47 | std::queue<std::function<void()>> work_queue_ TF_GUARDED_BY(mu_); |
| 48 | |
| 49 | std::unique_ptr<tensorflow::Thread> thread_; |
| 50 | }; |
| 51 | |
| 52 | } // namespace xla |
| 53 |
no outgoing calls
no test coverage detected