summaryrefslogtreecommitdiff
path: root/indra/llcommon/threadpool.cpp
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2022-06-09 10:18:29 -0400
committerNat Goodspeed <nat@lindenlab.com>2022-06-09 10:18:29 -0400
commitac99e979f43d49402a24b2f58a154c4ef1583efd (patch)
tree869ac8f37c9bcec53f8256a310492169bef5119b /indra/llcommon/threadpool.cpp
parentef87eb7fa80a72b94d67d5ab680f60a837dd1ddd (diff)
SL-17483: Make it possible to override width of any ThreadPool.
Introduce CommonControl, which in a running viewer (or any program containing an LLViewerControlListener instance) gives access to LLViewerControl functionality, e.g. getting, setting or enumerating control variables -- without introducing a link dependency on newview. Make ThreadPool's constructor consult CommonControl to check for an override for the width of the new ThreadPool in the Global (i.e. gSavedSettings) setting ThreadPoolSizes, and honor that if found. Introduce static ThreadPool methods getConfiguredWidth(), to query for such an override on any particular ThreadPool name; and getWidth(), to ask for the width of an instance if that instance already exists, else the width with which it *would* be instantiated.
Diffstat (limited to 'indra/llcommon/threadpool.cpp')
-rw-r--r--indra/llcommon/threadpool.cpp51
1 files changed, 50 insertions, 1 deletions
diff --git a/indra/llcommon/threadpool.cpp b/indra/llcommon/threadpool.cpp
index d5adf11264..10d67abf37 100644
--- a/indra/llcommon/threadpool.cpp
+++ b/indra/llcommon/threadpool.cpp
@@ -17,15 +17,17 @@
// std headers
// external library headers
// other Linden headers
+#include "commoncontrol.h"
#include "llerror.h"
#include "llevents.h"
+#include "llsd.h"
#include "stringize.h"
LL::ThreadPool::ThreadPool(const std::string& name, size_t threads, size_t capacity):
super(name),
mQueue(name, capacity),
mName("ThreadPool:" + name),
- mThreadCount(threads)
+ mThreadCount(getConfiguredWidth(name, threads))
{}
void LL::ThreadPool::start()
@@ -87,3 +89,50 @@ void LL::ThreadPool::run()
{
mQueue.runUntilClose();
}
+
+//static
+size_t LL::ThreadPool::getConfiguredWidth(const std::string& name, size_t dft=0)
+{
+ LLSD poolSizes{ LL::CommonControl::get("Global", "ThreadPoolSizes") };
+ // "ThreadPoolSizes" is actually a map containing the sizes of interest --
+ // or should be, if this process has an "LLViewerControl" LLEventAPI
+ // instance and its settings include "ThreadPoolSizes". If we failed to
+ // retrieve it, perhaps we're in a program that doesn't define that, or
+ // perhaps there's no such setting, or perhaps we're asking too early,
+ // before the LLEventAPI itself has been instantiated. In any of those
+ // cases, it seems worth warning.
+ if (! poolSizes.isDefined())
+ {
+ // Note: we don't warn about absence of an override key for a
+ // particular ThreadPool name, that's fine. This warning is about
+ // complete absence of a ThreadPoolSizes setting, which we expect in a
+ // normal viewer session.
+ LL_WARNS("ThreadPool") << "No 'ThreadPoolSizes' setting for ThreadPool '"
+ << name << "'" << LL_ENDL;
+ }
+ else
+ {
+ //LL_DEBUGS
+ LL_INFOS("ThreadPool") << "ThreadPoolSizes = " << poolSizes << LL_ENDL;
+ }
+ // LLSD treats an undefined value as an empty map when asked to retrieve a
+ // key, so we don't need this to be conditional.
+ LLSD sizeSpec{ poolSizes[name] };
+ // We retrieve sizeSpec as LLSD, rather than immediately as LLSD::Integer,
+ // so we can distinguish the case when it's undefined.
+ return sizeSpec.isInteger() ? sizeSpec.asInteger() : dft;
+}
+
+//static
+size_t LL::ThreadPool::getWidth(const std::string& name, size_t dft)
+{
+ auto instance{ getInstance(name) };
+ if (instance)
+ {
+ return instance->getWidth();
+ }
+ else
+ {
+ return getConfiguredWidth(name, dft);
+ }
+}