| 167 | } |
| 168 | |
| 169 | void Schedule(int64 num_threads, std::function<void()> fn) { |
| 170 | std::unique_lock<std::mutex> lock(mu_); |
| 171 | if (threads_) { |
| 172 | lock.unlock(); |
| 173 | threads_->Schedule(fn); |
| 174 | return; |
| 175 | } |
| 176 | |
| 177 | threads_.reset( |
| 178 | new thread::ThreadPool(Env::Default(), ThreadOptions(), |
| 179 | strings::StrCat("work_queue_threads_", name_), |
| 180 | num_threads, false /* low_latency_hint */)); |
| 181 | |
| 182 | lock.unlock(); |
| 183 | threads_->Schedule(fn); |
| 184 | } |
| 185 | |
| 186 | private: |
| 187 | // TODO(yuanman.ym): Use memory efficient data structure, e.g. HAT-trie, |
no test coverage detected