Skip to content

Commit

Permalink
GH-2048 Support const
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Jan 19, 2024
1 parent 4f634cd commit 7ec302e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ struct controller_impl {
chainbase::database db;
block_log blog;
std::optional<pending_state> pending;
mutable fork_database fork_db;
fork_database fork_db;
std::optional<chain_pacemaker> pacemaker;
std::atomic<uint32_t> if_irreversible_block_num{0};
resource_limits_manager resource_limits;
Expand Down
9 changes: 9 additions & 0 deletions libraries/chain/include/eosio/chain/fork_database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ namespace eosio::chain {
return std::visit([&](auto& forkdb) -> R { return f(forkdb); }, v);
}

template <class R, class F>
R apply(const F& f) const {
std::lock_guard g(m);
if constexpr (std::is_same_v<void, R>)
std::visit([&](const auto& forkdb) { f(forkdb); }, v);
else
return std::visit([&](const auto& forkdb) -> R { return f(forkdb); }, v);
}

template <class R, class F>
R apply_if(const F& f) {
if constexpr (std::is_same_v<void, R>)
Expand Down

0 comments on commit 7ec302e

Please sign in to comment.