Kagome
Polkadot Runtime Engine in C++17
rpc_thread_pool.cpp
Go to the documentation of this file.
1 
7 
8 #include <fmt/format.h>
9 #include <soralog/util.hpp>
10 
11 namespace kagome::api {
12 
13  RpcThreadPool::RpcThreadPool(std::shared_ptr<Context> context,
14  const Configuration &configuration)
15  : context_(std::move(context)), config_(configuration) {
16  BOOST_ASSERT(context_);
17  }
18 
21  // Create a pool of threads to run all of the io_contexts.
22  for (std::size_t i = 0; i < config_.min_thread_number; ++i) {
23  auto thread = std::make_shared<std::thread>([context = context_,
24  rpc_thread_number = i + 1] {
25  soralog::util::setThreadName(fmt::format("rpc.{}", rpc_thread_number));
26  context->run();
27  });
28  thread->detach();
29  threads_.emplace_back(std::move(thread));
30  }
31  SL_DEBUG(logger_, "Thread pool started");
32  }
33 
35  context_->stop();
36  SL_DEBUG(logger_, "Thread pool stopped");
37  }
38 
39 } // namespace kagome::api
std::vector< std::shared_ptr< std::thread > > threads_
RpcThreadPool(std::shared_ptr< Context > context, const Configuration &configuration)
std::shared_ptr< Context > context_
STL namespace.
const Configuration config_