Skip to content
Snippets Groups Projects
Commit c1458713 authored by Nat Goodspeed's avatar Nat Goodspeed
Browse files

DRTVWR-418: Make LLEventPumps an LLHandleProvider for LLEventPump.

LLEventPump's destructor was using LLEventPumps::instance() to unregister the
LLEventPump instance from LLEventPumps. Evidently, though, there are lingering
LLEventPump instances that persist even after the LLSingletonBase::deleteAll()
call destroys the LLEventPumps LLSingleton instance. These were resurrecting
LLEventPumps -- pointlessly, since a newly-resurrected LLEventPumps instance
can have no knowledge of the LLEventPump instance! Unregistering is
unnecessary!

What we want is a reference we can bind into each LLEventPump instance that
allows us to safely test whether the LLEventPumps instance still exists.
LLHandle is exactly that. Make LLEventPumps an LLHandleProvider and bind its
LLHandle in each LLEventPump's constructor; then the destructor can unregister
only when LLEventPumps still exists.
parent e6fc3528
No related branches found
No related tags found
No related merge requests found
...@@ -281,7 +281,8 @@ const std::string LLEventPump::ANONYMOUS = std::string(); ...@@ -281,7 +281,8 @@ const std::string LLEventPump::ANONYMOUS = std::string();
LLEventPump::LLEventPump(const std::string& name, bool tweak): LLEventPump::LLEventPump(const std::string& name, bool tweak):
// Register every new instance with LLEventPumps // Register every new instance with LLEventPumps
mName(LLEventPumps::instance().registerNew(*this, name, tweak)), mRegistry(LLEventPumps::instance().getHandle()),
mName(mRegistry.get()->registerNew(*this, name, tweak)),
mSignal(new LLStandardSignal()), mSignal(new LLStandardSignal()),
mEnabled(true) mEnabled(true)
{} {}
...@@ -292,8 +293,13 @@ LLEventPump::LLEventPump(const std::string& name, bool tweak): ...@@ -292,8 +293,13 @@ LLEventPump::LLEventPump(const std::string& name, bool tweak):
LLEventPump::~LLEventPump() LLEventPump::~LLEventPump()
{ {
// Unregister this doomed instance from LLEventPumps // Unregister this doomed instance from LLEventPumps -- but only if
LLEventPumps::instance().unregister(*this); // LLEventPumps is still around!
LLEventPumps* registry = mRegistry.get();
if (registry)
{
registry->unregister(*this);
}
} }
// static data member // static data member
......
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
#include "lldependencies.h" #include "lldependencies.h"
#include "llstl.h" #include "llstl.h"
#include "llexception.h" #include "llexception.h"
#include "llhandle.h"
/*==========================================================================*| /*==========================================================================*|
// override this to allow binding free functions with more parameters // override this to allow binding free functions with more parameters
...@@ -227,7 +228,15 @@ class LLEventPump; ...@@ -227,7 +228,15 @@ class LLEventPump;
* LLEventPumps is a Singleton manager through which one typically accesses * LLEventPumps is a Singleton manager through which one typically accesses
* this subsystem. * this subsystem.
*/ */
class LL_COMMON_API LLEventPumps: public LLSingleton<LLEventPumps> // LLEventPumps isa LLHandleProvider only for (hopefully rare) long-lived
// class objects that must refer to this class late in their lifespan, say in
// the destructor. Specifically, the case that matters is a possible reference
// after LLEventPumps::deleteSingleton(). (Lingering LLEventPump instances are
// capable of this.) In that case, instead of calling LLEventPumps::instance()
// again -- resurrecting the deleted LLSingleton -- store an
// LLHandle<LLEventPumps> and test it before use.
class LL_COMMON_API LLEventPumps: public LLSingleton<LLEventPumps>,
public LLHandleProvider<LLEventPumps>
{ {
LLSINGLETON(LLEventPumps); LLSINGLETON(LLEventPumps);
public: public:
...@@ -590,6 +599,9 @@ class LL_COMMON_API LLEventPump: public LLEventTrackable ...@@ -590,6 +599,9 @@ class LL_COMMON_API LLEventPump: public LLEventTrackable
return this->listen_impl(name, listener, after, before); return this->listen_impl(name, listener, after, before);
} }
// must precede mName; see LLEventPump::LLEventPump()
LLHandle<LLEventPumps> mRegistry;
std::string mName; std::string mName;
protected: protected:
...@@ -817,14 +829,14 @@ class LL_COMMON_API LLListenerWrapperBase ...@@ -817,14 +829,14 @@ class LL_COMMON_API LLListenerWrapperBase
mConnection(new LLBoundListener) mConnection(new LLBoundListener)
{ {
} }
/// Copy constructor. Copy shared_ptrs to original instance data. /// Copy constructor. Copy shared_ptrs to original instance data.
LLListenerWrapperBase(const LLListenerWrapperBase& that): LLListenerWrapperBase(const LLListenerWrapperBase& that):
mName(that.mName), mName(that.mName),
mConnection(that.mConnection) mConnection(that.mConnection)
{ {
} }
virtual ~LLListenerWrapperBase() {} virtual ~LLListenerWrapperBase() {}
/// Ask LLEventPump::listen() for the listener name /// Ask LLEventPump::listen() for the listener name
virtual void accept_name(const std::string& name) const virtual void accept_name(const std::string& name) const
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment