Add an InstanceSettings::NotifyOwnerIsShuttingDown() method so that the owner can notify InstanceSettings instances

that their owner reference is no longer valid.

llvm-svn: 149145
This commit is contained in:
Johnny Chen 2012-01-27 21:27:39 +00:00
parent 376a2d3e99
commit aefcf999d2
2 changed files with 17 additions and 2 deletions

View File

@ -399,6 +399,9 @@ public:
// Begin Pure Virtual Functions
virtual void
NotifyOwnerIsShuttingDown ();
virtual void
UpdateInstanceSettingsVariable (const ConstString &var_name,
const char *index_value,
@ -440,6 +443,7 @@ public:
protected:
UserSettingsController &m_owner;
bool m_owner_is_live;
ConstString m_instance_name;
};

View File

@ -83,6 +83,10 @@ UserSettingsController::UserSettingsController (const char *level_name,
UserSettingsController::~UserSettingsController ()
{
Mutex::Locker locker (m_live_settings_mutex);
// Notify all instance settings that their owner is shutting down, first.
for (InstanceSettingsMap::iterator pos = m_live_settings.begin(); pos != m_live_settings.end(); ++pos)
pos->second->NotifyOwnerIsShuttingDown();
m_live_settings.clear();
}
@ -2458,7 +2462,8 @@ UserSettingsController::RenameInstanceSettings (const char *old_name, const char
InstanceSettings::InstanceSettings (UserSettingsController &owner, const char *instance_name, bool live_instance) :
m_owner (owner),
m_instance_name (instance_name)
m_instance_name (instance_name),
m_owner_is_live (true)
{
if ((m_instance_name != InstanceSettings::GetDefaultName())
&& (m_instance_name != InstanceSettings::InvalidName())
@ -2468,10 +2473,16 @@ InstanceSettings::InstanceSettings (UserSettingsController &owner, const char *i
InstanceSettings::~InstanceSettings ()
{
if (m_instance_name != InstanceSettings::GetDefaultName())
if (m_instance_name != InstanceSettings::GetDefaultName() && m_owner_is_live)
m_owner.UnregisterInstanceSettings (this);
}
void
InstanceSettings::NotifyOwnerIsShuttingDown()
{
m_owner_is_live = false;
}
const ConstString &
InstanceSettings::GetDefaultName ()
{