diff --git a/benchmarks/init.cpp b/benchmarks/init.cpp index 9b29413..48bf505 100644 --- a/benchmarks/init.cpp +++ b/benchmarks/init.cpp @@ -87,6 +87,7 @@ auto BMInitialise(benchmark::State& state) { for(auto _ : state) { auto* ptr = new (context) ServiceContextType{}; ptr->Run(); + ptr->FindComponent().ioContext.run(); state.PauseTiming(); ptr->~ServiceContextType(); state.ResumeTiming(); diff --git a/include/cserver/engine/basic/task_processor.hpp b/include/cserver/engine/basic/task_processor.hpp index d67d96d..4d69dad 100644 --- a/include/cserver/engine/basic/task_processor.hpp +++ b/include/cserver/engine/basic/task_processor.hpp @@ -1,13 +1,14 @@ #pragma once #include #include +#include namespace cserver::engine::basic { template struct TaskProcessor { boost::asio::io_context ioContext; - std::array pool; + std::array, Size> pool; static constexpr utempl::ConstexprString kName = "basicTaskProcessor"; inline constexpr TaskProcessor(auto, auto&) : ioContext{}, @@ -15,16 +16,22 @@ struct TaskProcessor { }; inline constexpr ~TaskProcessor() { - this->ioContext.stop(); for(auto& thread : this->pool) { - thread.join(); + if(thread && thread->joinable()) { + thread->join(); + }; }; }; inline auto Run() { for(auto& thread : this->pool) { - thread = std::thread([&]{ - boost::asio::executor_work_guardioContext.get_executor())> guard{this->ioContext.get_executor()}; + if(this->ioContext.stopped()) { + return; + }; + thread = std::jthread([&]{ + if(this->ioContext.stopped()) { + return; + }; this->ioContext.run(); }); };