Clean up after Linden Lab

This commit is contained in:
Aleric Inglewood
2012-02-23 18:46:44 +01:00
parent 2206f68129
commit 0450358df3
2 changed files with 25 additions and 9 deletions

View File

@@ -244,17 +244,31 @@ void LLEventPumps::unregister(const LLEventPump& pump)
} }
} }
//static
bool LLEventPumps::sDeleted;
//static
void LLEventPumps::maybe_unregister(const LLEventPump& pump)
{
if (!sDeleted)
{
LLEventPumps::instance().unregister(pump);
}
}
LLEventPumps::~LLEventPumps() LLEventPumps::~LLEventPumps()
{ {
// On destruction, delete every LLEventPump we instantiated (via // Deleting an LLEventPump calls its destructor, which calls maybe_unregister(),
// obtain()). CAREFUL: deleting an LLEventPump calls its destructor, which // which would try to remove that LLEventPump instance from a NEWLY created LLEventPumps
// calls unregister(), which removes that LLEventPump instance from // singleton (as we're already being destructed). Therefore, mark that we're not
// mOurPumps. So an iterator loop over mOurPumps to delete contained // home anymore... --Aleric
// LLEventPump instances is dangerous! Instead, delete them one at a time sDeleted = true;
// until mOurPumps is empty.
while (! mOurPumps.empty()) // Subsequently we can delete every LLEventPump we instantiated (via obtain()).
// We're not clearing mPumpMap or mOurPumps here... their destructors will.
for (LLEventPumps::PumpSet::iterator pump = mOurPumps.begin(); pump != mOurPumps.end(); ++pump)
{ {
delete *mOurPumps.begin(); delete *pump;
} }
} }
@@ -280,7 +294,7 @@ LLEventPump::LLEventPump(const std::string& name, bool tweak):
LLEventPump::~LLEventPump() LLEventPump::~LLEventPump()
{ {
// Unregister this doomed instance from LLEventPumps // Unregister this doomed instance from LLEventPumps
LLEventPumps::instance().unregister(*this); LLEventPumps::maybe_unregister(*this);
} }
// static data member // static data member

View File

@@ -238,6 +238,8 @@ private:
* Unregister a doomed LLEventPump instance (internal) * Unregister a doomed LLEventPump instance (internal)
*/ */
void unregister(const LLEventPump&); void unregister(const LLEventPump&);
static bool sDeleted;
static void maybe_unregister(const LLEventPump&);
private: private:
LLEventPumps(); LLEventPumps();