| 25 | : stream_(stream), thread_pool_(new ::ThreadPool(1)) {} |
| 26 | |
| 27 | void CallbackManager::AddCallback(std::function<void()> callback) const { |
| 28 | auto *callback_func = new std::function<void()>(std::move(callback)); |
| 29 | auto *func = new std::function<void()>([this, callback_func] { |
| 30 | std::lock_guard<std::mutex> lock(mtx_); |
| 31 | last_future_ = thread_pool_->enqueue([callback_func] { |
| 32 | std::unique_ptr<std::function<void()>> releaser(callback_func); |
| 33 | (*callback_func)(); |
| 34 | }); |
| 35 | }); |
| 36 | phi::DeviceGuard guard(stream_->GetPlace()); |
| 37 | DeviceManager::GetDeviceWithPlace(stream_->GetPlace()) |
| 38 | ->AddCallback(stream_, func); |
| 39 | } |
| 40 | |
| 41 | void CallbackManager::Wait() const { |
| 42 | phi::DeviceGuard guard(stream_->GetPlace()); |