diff options
author | Andrey Lihatskiy <alihatskiy@productengine.com> | 2025-04-23 01:27:32 +0300 |
---|---|---|
committer | Andrey Lihatskiy <alihatskiy@productengine.com> | 2025-04-23 18:56:27 +0300 |
commit | ec6c988bbbc59aed218d3629bf0c13192f6b726c (patch) | |
tree | 319bf357249da12f0934440bc53741fde605c335 | |
parent | 1e4f12fc811ff534fd2013c7573ba930ae29b589 (diff) |
#3918 Implement automatic shutdown for WorkQueueBase
-rw-r--r-- | indra/llcommon/workqueue.cpp | 31 | ||||
-rw-r--r-- | indra/llcommon/workqueue.h | 5 |
2 files changed, 33 insertions, 3 deletions
diff --git a/indra/llcommon/workqueue.cpp b/indra/llcommon/workqueue.cpp index 323903e59c..0eb20323ad 100644 --- a/indra/llcommon/workqueue.cpp +++ b/indra/llcommon/workqueue.cpp @@ -21,6 +21,7 @@ #include "llcoros.h" #include LLCOROS_MUTEX_HEADER #include "llerror.h" +#include "llevents.h" #include "llexception.h" #include "stringize.h" @@ -34,10 +35,34 @@ LL::WorkQueueBase::WorkQueueBase(const std::string& name, bool auto_shutdown) : super(makeName(name)) { if (auto_shutdown) -{ - // TODO: register for "LLApp" events so we can implicitly close() on - // viewer shutdown. + { + // Register for "LLApp" events so we can implicitly close() on viewer shutdown + std::string listener_name = "WorkQueue:" + getKey(); + LLEventPumps::instance().obtain("LLApp").listen( + listener_name, + [this](const LLSD& stat) + { + std::string status(stat["status"]); + if (status != "running") + { + // Viewer is shutting down, close this queue + LL_DEBUGS("WorkQueue") << getKey() << " closing on app shutdown" << LL_ENDL; + close(); + } + return false; + }); + + // Store the listener name so we can unregister in the destructor + mListenerName = listener_name; + } } + +LL::WorkQueueBase::~WorkQueueBase() +{ + if (!mListenerName.empty() && !LLEventPumps::wasDeleted()) + { + LLEventPumps::instance().obtain("LLApp").stopListening(mListenerName); + } } void LL::WorkQueueBase::runUntilClose() diff --git a/indra/llcommon/workqueue.h b/indra/llcommon/workqueue.h index d424ca6e1c..735ad38a26 100644 --- a/indra/llcommon/workqueue.h +++ b/indra/llcommon/workqueue.h @@ -53,6 +53,8 @@ namespace LL */ WorkQueueBase(const std::string& name, bool auto_shutdown); + virtual ~WorkQueueBase(); + /** * Since the point of WorkQueue is to pass work to some other worker * thread(s) asynchronously, it's important that it continue to exist @@ -197,6 +199,9 @@ namespace LL private: virtual Work pop_() = 0; virtual bool tryPop_(Work&) = 0; + + // Name used for the LLApp event listener (empty if not registered) + std::string mListenerName; }; /***************************************************************************** |