Kagome
Polkadot Runtime Engine in C++17
offchain_worker_pool_impl.cpp
Go to the documentation of this file.
1 
7 
8 namespace kagome::offchain {
9 
10  using soralog::util::getThreadNumber;
11 
13  : log_(log::createLogger("OffchainWorkerPool", "offchain")) {
14  BOOST_ASSERT(log_);
15  }
16 
17  void OffchainWorkerPoolImpl::addWorker(std::shared_ptr<OffchainWorker> ofw) {
18  offchain_workers_.exclusiveAccess([&](auto &offchain_workers) {
19  offchain_workers.emplace(getThreadNumber(), std::move(ofw));
20  });
21  }
22 
23  std::optional<std::shared_ptr<OffchainWorker>>
25  return offchain_workers_.sharedAccess(
26  [](auto const &offchain_workers)
27  -> std::optional<std::shared_ptr<OffchainWorker>> {
28  if (auto it = offchain_workers.find(getThreadNumber());
29  it != offchain_workers.end())
30  return it->second;
31  return std::nullopt;
32  });
33  }
34 
36  return offchain_workers_.exclusiveAccess([&](auto &offchain_workers) {
37  return offchain_workers.erase(getThreadNumber()) == 1;
38  });
39  }
40 
41 } // namespace kagome::offchain
void addWorker(std::shared_ptr< OffchainWorker > ofw) override
SafeObject< std::unordered_map< ThreadNumber, std::shared_ptr< OffchainWorker > > > offchain_workers_
Logger createLogger(const std::string &tag)
Definition: logger.cpp:112
std::optional< std::shared_ptr< OffchainWorker > > getWorker() const override