diff options
| author | Nat Goodspeed <nat@lindenlab.com> | 2021-11-05 12:33:31 -0400 | 
|---|---|---|
| committer | Nat Goodspeed <nat@lindenlab.com> | 2021-11-05 12:33:31 -0400 | 
| commit | ff5496239bffadaca111b1e4380a01447f85843a (patch) | |
| tree | 990a2b72d8eea23f6ef7539079c515aab30625ac /indra/llcommon | |
| parent | 834e7ca088b5f417235327cd290b42459c733594 (diff) | |
SL-16202: Use WorkQueue::postTo() for texture create/post handshake.
That is, when LLViewerFetchedTexture::scheduleCreateTexture() wants to call
createTexture() on the LLImageGLThread, but postCreateTexture() on the main
thread, use the "mainloop" WorkQueue to set up the handshake.
Give ThreadPool a public virtual run() method so a subclass can override with
desired behavior. This necessitates a virtual destructor. Add accessors for
embedded WorkQueue (for post calls), ThreadPool name and width (in threads).
Allow LLSimpleton::createInstance() to forward arguments to the subject
constructor.
Make LLImageGLThread an LLSimpleton - that abstraction didn't yet exist at the
time LLImageGLThread was coded. Also derive from ThreadPool rather than
LLThread. Make it a single-thread "pool" with a very large queue capacity.
Diffstat (limited to 'indra/llcommon')
| -rw-r--r-- | indra/llcommon/llsingleton.h | 20 | ||||
| -rw-r--r-- | indra/llcommon/threadpool.cpp | 7 | ||||
| -rw-r--r-- | indra/llcommon/threadpool.h | 18 | 
3 files changed, 34 insertions, 11 deletions
| diff --git a/indra/llcommon/llsingleton.h b/indra/llcommon/llsingleton.h index 24d01812c9..fdd5bdfea9 100644 --- a/indra/llcommon/llsingleton.h +++ b/indra/llcommon/llsingleton.h @@ -847,22 +847,24 @@ template<class T>  class LLSimpleton  {  public: -    static T* sInstance; -     -    static void createInstance()  -    {  +    template <typename... ARGS> +    static void createInstance(ARGS&&... args) +    {          llassert(sInstance == nullptr); -        sInstance = new T();  +        sInstance = new T(std::forward<ARGS>(args)...);      } -     +      static inline T* getInstance() { return sInstance; }      static inline T& instance() { return *getInstance(); }      static inline bool instanceExists() { return sInstance != nullptr; } -    static void deleteSingleton() {  -        delete sInstance;  -        sInstance = nullptr;  +    static void deleteSingleton() { +        delete sInstance; +        sInstance = nullptr;      } + +private: +    static T* sInstance;  };  template <class T> diff --git a/indra/llcommon/threadpool.cpp b/indra/llcommon/threadpool.cpp index e4fa0eccf3..cf25cc838e 100644 --- a/indra/llcommon/threadpool.cpp +++ b/indra/llcommon/threadpool.cpp @@ -70,6 +70,11 @@ void LL::ThreadPool::close()  void LL::ThreadPool::run(const std::string& name)  {      LL_DEBUGS("ThreadPool") << name << " starting" << LL_ENDL; -    mQueue.runUntilClose(); +    run();      LL_DEBUGS("ThreadPool") << name << " stopping" << LL_ENDL;  } + +void LL::ThreadPool::run() +{ +    mQueue.runUntilClose(); +} diff --git a/indra/llcommon/threadpool.h b/indra/llcommon/threadpool.h index 6e3858508b..1ca24aec58 100644 --- a/indra/llcommon/threadpool.h +++ b/indra/llcommon/threadpool.h @@ -30,9 +30,25 @@ namespace LL           * relevant WorkQueue.           */          ThreadPool(const std::string& name, size_t threads=1, size_t capacity=1024); -        ~ThreadPool(); +        virtual ~ThreadPool(); + +        /** +         * ThreadPool listens for application shutdown messages on the "LLApp" +         * LLEventPump. Call close() to shut down this ThreadPool early. +         */          void close(); +        std::string getName() const { return mName; } +        size_t getWidth() const { return mThreads.size(); } +        /// obtain a non-const reference to the WorkQueue to post work to it +        WorkQueue& getQueue() { return mQueue; } + +        /** +         * Override run() if you need special processing. The default run() +         * implementation simply calls WorkQueue::runUntilClose(). +         */ +        virtual void run(); +      private:          void run(const std::string& name); | 
