Kagome
Polkadot Runtime Engine in C++17
kagome::runtime::RuntimeInstancesPool Class Referencefinal

Pool of runtime instances - per state. Incapsulates modules cache. More...

#include <runtime_instances_pool.hpp>

Inheritance diagram for kagome::runtime::RuntimeInstancesPool:
Collaboration diagram for kagome::runtime::RuntimeInstancesPool:

Public Types

using RootHash = storage::trie::RootHash
 
using ModuleCache = SmallLruCache< storage::trie::RootHash, std::shared_ptr< Module >>
 

Public Member Functions

outcome::result< std::shared_ptr< ModuleInstance > > tryAcquire (const RootHash &state)
 Instantiate new or reuse existing ModuleInstance for the provided state. More...
 
void release (const RootHash &state, std::shared_ptr< ModuleInstance > &&instance)
 Releases the module instance (returns it to the pool) More...
 
std::optional< std::shared_ptr< Module > > getModule (const RootHash &state)
 Get the module for state from internal cache. More...
 
void putModule (const RootHash &state, std::shared_ptr< Module > module)
 Puts new module into internal cache. More...
 

Private Types

using ModuleInstancePool = std::stack< std::shared_ptr< ModuleInstance >>
 

Private Attributes

std::mutex mt_
 
ModuleCache modules_ {MODULES_CACHE_SIZE}
 
std::map< RootHash, ModuleInstancePoolpools_
 

Static Private Attributes

static constexpr size_t MODULES_CACHE_SIZE = 2
 

Detailed Description

Pool of runtime instances - per state. Incapsulates modules cache.

Definition at line 86 of file runtime_instances_pool.hpp.

Member Typedef Documentation

using kagome::runtime::RuntimeInstancesPool::ModuleInstancePool = std::stack<std::shared_ptr<ModuleInstance>>
private

Definition at line 88 of file runtime_instances_pool.hpp.

Member Function Documentation

std::optional< std::shared_ptr< Module > > kagome::runtime::RuntimeInstancesPool::getModule ( const RootHash state)

Get the module for state from internal cache.

Parameters
state- the state containing the module's code.
Returns
Module if any, nullopt otherwise

Definition at line 98 of file runtime_instances_pool.cpp.

void kagome::runtime::RuntimeInstancesPool::putModule ( const RootHash state,
std::shared_ptr< Module module 
)

Puts new module into internal cache.

Parameters
state- runtime block, by its root hash
module- new module pointer

Definition at line 104 of file runtime_instances_pool.cpp.

void kagome::runtime::RuntimeInstancesPool::release ( const RootHash state,
std::shared_ptr< ModuleInstance > &&  instance 
)

Releases the module instance (returns it to the pool)

Parameters
state- the merkle trie root of the state containing the runtime module code we are releasing an instance of.
instance- instance to be released.

Definition at line 89 of file runtime_instances_pool.cpp.

outcome::result< std::shared_ptr< ModuleInstance > > kagome::runtime::RuntimeInstancesPool::tryAcquire ( const RootHash state)

Instantiate new or reuse existing ModuleInstance for the provided state.

Parameters
state- the merkle trie root of the state containing the code of the runtime module we are acquiring an instance of.
Returns
pointer to the acquired ModuleInstance if success. Error otherwise.

Definition at line 68 of file runtime_instances_pool.cpp.

Member Data Documentation

ModuleCache kagome::runtime::RuntimeInstancesPool::modules_ {MODULES_CACHE_SIZE}
private

Definition at line 135 of file runtime_instances_pool.hpp.

constexpr size_t kagome::runtime::RuntimeInstancesPool::MODULES_CACHE_SIZE = 2
staticprivate

Definition at line 134 of file runtime_instances_pool.hpp.

std::mutex kagome::runtime::RuntimeInstancesPool::mt_
private

Definition at line 133 of file runtime_instances_pool.hpp.

std::map<RootHash, ModuleInstancePool> kagome::runtime::RuntimeInstancesPool::pools_
private

Definition at line 136 of file runtime_instances_pool.hpp.


The documentation for this class was generated from the following files: