You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
- #include <ecs/core/utils/fixed_function.inl>
- #include <ecs/core/utils/thread_pool/pool.inl>
- #include <ecs/core/utils/thread_pool/worker.inl>
-
- using namespace ::ecs::core::utils;
-
- auto thread_pool
- ::all_workers_finished() const noexcept
- {
- for (const auto& w : _workers)
- {
- if (!w->finished())
- {
- return false;
- }
- }
- return true;
- }
-
- void thread_pool
- ::initialize_workers(size_t count)
- {
- _workers.reserve(count);
- for (size_t i = 0; i < count; ++i)
- {
- _workers.emplace_back(std::make_unique<thread_pool_worker>(_tasks, i + 1));
- }
-
- _outstanding_inits = count;
- for (auto& w : _workers)
- {
- w->start(_outstanding_inits);
- }
- }
-
- thread_pool
- ::thread_pool(size_t count)
- {
- assert(count > 1);
- initialize_workers(count);
- }
-
- thread_pool
- ::~thread_pool()
- {
- // wait for uninitialized workers
- while (_outstanding_inits > 0)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(50));
- }
-
- // join the worker threads
- for (auto& w : _workers)
- {
- w->stop();
- w->signal();
- w->join();
- }
- }
|