Permalink
Browse files

Clean up after Linden Lab

  • Loading branch information...
1 parent 2206f68 commit 0450358df398054b24f0c84cf52bc835c0c21b37 @AlericInglewood committed Feb 23, 2012
Showing with 25 additions and 9 deletions.
  1. +23 −9 indra/llcommon/llevents.cpp
  2. +2 −0 indra/llcommon/llevents.h
@@ -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()
{
- // On destruction, delete every LLEventPump we instantiated (via
- // obtain()). CAREFUL: deleting an LLEventPump calls its destructor, which
- // calls unregister(), which removes that LLEventPump instance from
- // mOurPumps. So an iterator loop over mOurPumps to delete contained
- // LLEventPump instances is dangerous! Instead, delete them one at a time
- // until mOurPumps is empty.
- while (! mOurPumps.empty())
+ // Deleting an LLEventPump calls its destructor, which calls maybe_unregister(),
+ // which would try to remove that LLEventPump instance from a NEWLY created LLEventPumps
+ // singleton (as we're already being destructed). Therefore, mark that we're not
+ // home anymore... --Aleric
+ sDeleted = true;
+
+ // 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()
{
// Unregister this doomed instance from LLEventPumps
- LLEventPumps::instance().unregister(*this);
+ LLEventPumps::maybe_unregister(*this);
}
// static data member
@@ -238,6 +238,8 @@ class LL_COMMON_API LLEventPumps: public LLSingleton<LLEventPumps>
* Unregister a doomed LLEventPump instance (internal)
*/
void unregister(const LLEventPump&);
+ static bool sDeleted;
+ static void maybe_unregister(const LLEventPump&);
private:
LLEventPumps();

0 comments on commit 0450358

Please sign in to comment.