6 #ifndef KAGOME_CORE_RUNTIME_INSTANCES_POOL_HPP 7 #define KAGOME_CORE_RUNTIME_INSTANCES_POOL_HPP 17 template <
typename Key,
typename Value,
typename PriorityType = u
int64_t>
20 static_assert(std::is_unsigned_v<PriorityType>);
37 std::optional<std::reference_wrapper<const Value>>
get(
const Key &
key) {
42 for (
auto &entry :
cache_) {
43 if (entry.key ==
key) {
44 entry.latest_use_tick_ =
ticks_;
51 template <
typename ValueArg>
53 static_assert(std::is_convertible_v<
55 Value> || std::is_constructible_v<ValueArg, Value>);
58 auto min = std::min_element(
cache_.begin(),
cache_.end());
69 for (
auto &entry :
cache_) {
70 entry.latest_use_tick_ =
ticks_;
87 :
public std::enable_shared_from_this<RuntimeInstancesPool> {
104 outcome::result<std::shared_ptr<ModuleInstance>> tryAcquire(
114 std::shared_ptr<ModuleInstance> &&instance);
122 std::optional<std::shared_ptr<Module>> getModule(
const RootHash &state);
130 void putModule(
const RootHash &state, std::shared_ptr<Module> module);
134 static constexpr
size_t MODULES_CACHE_SIZE = 2;
136 std::map<RootHash, ModuleInstancePool>
pools_;
141 #endif // KAGOME_CORE_RUNTIME_INSTANCES_POOL_HPP
void handleTicksOverflow()
SmallLruCache(size_t max_size)
void put(const Key &key, ValueArg &&value)
bool operator<(const CacheEntry &rhs) const
std::vector< CacheEntry > cache_
std::stack< std::shared_ptr< ModuleInstance >> ModuleInstancePool
PriorityType latest_use_tick_
Pool of runtime instances - per state. Incapsulates modules cache.
std::map< RootHash, ModuleInstancePool > pools_