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

SL-793: Add LLEventPumps::clear() method to disconnect all listeners.

This is like the existing reset() method, except that reset() is specifically
intended for shutdown: it disables every existing LLEventPump in such a way
that it cannot be subsequently reused. (The original idea was to disconnect
listeners in DLLs unloaded at shutdown.)

clear() forcibly disconnects all existing listeners, but leaves LLEventPumps
ready for reuse. This is useful (e.g.) for test programs to reset the state of
LLEventPumps between individual test functions.
parent 66981fab
No related branches found
No related tags found
No related merge requests found
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include <cctype> #include <cctype>
// external library headers // external library headers
#include <boost/range/iterator_range.hpp> #include <boost/range/iterator_range.hpp>
#include <boost/make_shared.hpp>
#if LL_WINDOWS #if LL_WINDOWS
#pragma warning (push) #pragma warning (push)
#pragma warning (disable : 4701) // compiler thinks might use uninitialized var, but no #pragma warning (disable : 4701) // compiler thinks might use uninitialized var, but no
...@@ -154,13 +155,23 @@ void LLEventPumps::flush() ...@@ -154,13 +155,23 @@ void LLEventPumps::flush()
} }
} }
void LLEventPumps::clear()
{
// Clear every known LLEventPump instance. Leave it up to each instance to
// decide what to do with the clear() call.
for (PumpMap::value_type& pair : mPumpMap)
{
pair.second->clear();
}
}
void LLEventPumps::reset() void LLEventPumps::reset()
{ {
// Reset every known LLEventPump instance. Leave it up to each instance to // Reset every known LLEventPump instance. Leave it up to each instance to
// decide what to do with the reset() call. // decide what to do with the reset() call.
for (PumpMap::iterator pmi = mPumpMap.begin(), pmend = mPumpMap.end(); pmi != pmend; ++pmi) for (PumpMap::value_type& pair : mPumpMap)
{ {
pmi->second->reset(); pair.second->reset();
} }
} }
...@@ -283,7 +294,7 @@ LLEventPump::LLEventPump(const std::string& name, bool tweak): ...@@ -283,7 +294,7 @@ LLEventPump::LLEventPump(const std::string& name, bool tweak):
// Register every new instance with LLEventPumps // Register every new instance with LLEventPumps
mRegistry(LLEventPumps::instance().getHandle()), mRegistry(LLEventPumps::instance().getHandle()),
mName(mRegistry.get()->registerNew(*this, name, tweak)), mName(mRegistry.get()->registerNew(*this, name, tweak)),
mSignal(new LLStandardSignal()), mSignal(boost::make_shared<LLStandardSignal>()),
mEnabled(true) mEnabled(true)
{} {}
...@@ -311,6 +322,14 @@ std::string LLEventPump::inventName(const std::string& pfx) ...@@ -311,6 +322,14 @@ std::string LLEventPump::inventName(const std::string& pfx)
return STRINGIZE(pfx << suffix++); return STRINGIZE(pfx << suffix++);
} }
void LLEventPump::clear()
{
// Destroy the original LLStandardSignal instance, replacing it with a
// whole new one.
mSignal = boost::make_shared<LLStandardSignal>();
mConnections.clear();
}
void LLEventPump::reset() void LLEventPump::reset()
{ {
mSignal.reset(); mSignal.reset();
...@@ -553,7 +572,7 @@ bool LLEventMailDrop::post(const LLSD& event) ...@@ -553,7 +572,7 @@ bool LLEventMailDrop::post(const LLSD& event)
// be posted to any future listeners when they attach. // be posted to any future listeners when they attach.
mEventHistory.push_back(event); mEventHistory.push_back(event);
} }
return posted; return posted;
} }
......
...@@ -263,6 +263,11 @@ class LL_COMMON_API LLEventPumps: public LLSingleton<LLEventPumps>, ...@@ -263,6 +263,11 @@ class LL_COMMON_API LLEventPumps: public LLSingleton<LLEventPumps>,
*/ */
void flush(); void flush();
/**
* Disconnect listeners from all known LLEventPump instances
*/
void clear();
/** /**
* Reset all known LLEventPump instances * Reset all known LLEventPump instances
* workaround for DEV-35406 crash on shutdown * workaround for DEV-35406 crash on shutdown
...@@ -587,7 +592,7 @@ class LL_COMMON_API LLEventPump: public LLEventTrackable ...@@ -587,7 +592,7 @@ class LL_COMMON_API LLEventPump: public LLEventTrackable
private: private:
friend class LLEventPumps; friend class LLEventPumps;
virtual void clear();
virtual void reset(); virtual void reset();
......
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