| 76 | namespace agi::dispatch { |
| 77 | |
| 78 | void Init(std::function<void (Thunk)>&& invoke_main) { |
| 79 | static IOServiceThreadPool thread_pool; |
| 80 | ::service = &thread_pool.io_context; |
| 81 | ::invoke_main = invoke_main; |
| 82 | |
| 83 | thread_pool.threads.reserve(std::max<unsigned>(4, std::thread::hardware_concurrency())); |
| 84 | for (size_t i = 0; i < thread_pool.threads.capacity(); ++i) { |
| 85 | thread_pool.threads.emplace_back([]{ |
| 86 | ++threads_running; |
| 87 | agi::util::SetThreadName("Dispatch Worker"); |
| 88 | service->run(); |
| 89 | --threads_running; |
| 90 | }); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | void Queue::Async(Thunk&& thunk) { |
| 95 | DoInvoke([=] { |