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:
		@ -883,7 +883,7 @@ private:
 | 
				
			|||||||
    friend Type;
 | 
					    friend Type;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void insert(Type* pValue);
 | 
					    void insert(Type* pValue);
 | 
				
			||||||
    void remove(Type* pValue);
 | 
					    void remove(Type* pValue, const std::string& name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    std::string          m_name;
 | 
					    std::string          m_name;
 | 
				
			||||||
@ -948,6 +948,7 @@ protected:
 | 
				
			|||||||
private:
 | 
					private:
 | 
				
			||||||
    Configuration&    m_configuration;
 | 
					    Configuration&    m_configuration;
 | 
				
			||||||
    const Param&      m_param;
 | 
					    const Param&      m_param;
 | 
				
			||||||
 | 
					    const std::string m_name;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 | 
				
			|||||||
@ -381,11 +381,12 @@ void Configuration::insert(Type* pValue)
 | 
				
			|||||||
    m_values.insert(make_pair(pValue->parameter().name(), 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 != m_values.end());
 | 
				
			||||||
 | 
					    mxb_assert(it->second == pValue);
 | 
				
			||||||
    m_values.erase(it);
 | 
					    m_values.erase(it);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -405,13 +406,16 @@ size_t Configuration::size() const
 | 
				
			|||||||
Type::Type(Configuration* pConfiguration, const config::Param* pParam)
 | 
					Type::Type(Configuration* pConfiguration, const config::Param* pParam)
 | 
				
			||||||
    : m_configuration(*pConfiguration)
 | 
					    : m_configuration(*pConfiguration)
 | 
				
			||||||
    , m_param(*pParam)
 | 
					    , 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);
 | 
					    m_configuration.insert(this);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Type::~Type()
 | 
					Type::~Type()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    m_configuration.remove(this);
 | 
					    m_configuration.remove(this, m_name);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const config::Param& Type::parameter() const
 | 
					const config::Param& Type::parameter() const
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user