MXS-2612 Ensure that destructor order does not matter

The new configuration system relieas upon static varibles being
used for declaring what arguments a particular module uses. To
ensure that the destruction order does not matter, we redundantly
store the needed data (the name).
This commit is contained in:
Johan Wikman 2019-08-28 15:59:45 +03:00
parent 0bb53bf411
commit 5a7c68e3c9
2 changed files with 11 additions and 6 deletions

View File

@ -883,7 +883,7 @@ private:
friend Type;
void insert(Type* pValue);
void remove(Type* pValue);
void remove(Type* pValue, const std::string& name);
private:
std::string m_name;
@ -946,8 +946,9 @@ protected:
Type(Configuration* pConfiguration, const Param* pParam);
private:
Configuration& m_configuration;
const Param& m_param;
Configuration& m_configuration;
const Param& m_param;
const std::string m_name;
};
/**

View File

@ -381,11 +381,12 @@ void Configuration::insert(Type* pValue)
m_values.insert(make_pair(pValue->parameter().name(), pValue));
}
void Configuration::remove(Type* pValue)
void Configuration::remove(Type* pValue, const std::string& name)
{
auto it = m_values.find(pValue->parameter().name());
auto it = m_values.find(name);
mxb_assert(it != m_values.end());
mxb_assert(it->second == pValue);
m_values.erase(it);
}
@ -405,13 +406,16 @@ size_t Configuration::size() const
Type::Type(Configuration* pConfiguration, const config::Param* pParam)
: m_configuration(*pConfiguration)
, m_param(*pParam)
, m_name(pParam->name())
{
// The name is copied, so that we have access to it in the destructor
// also in the case that Param happens to be destructed first.
m_configuration.insert(this);
}
Type::~Type()
{
m_configuration.remove(this);
m_configuration.remove(this, m_name);
}
const config::Param& Type::parameter() const