diff options
author | Nat Goodspeed <nat@lindenlab.com> | 2021-11-04 16:50:31 -0400 |
---|---|---|
committer | Nat Goodspeed <nat@lindenlab.com> | 2021-11-04 16:50:31 -0400 |
commit | d848d9e888690210dd37a40c634820fd473699fb (patch) | |
tree | 91403c58f6f6bbae740a7ce0913c4f217d379536 /indra/llrender | |
parent | 89f2169e9d2c03ed92810689563ca110886abf16 (diff) |
SL-16202: Streamline WorkQueues in LLImageGLThread.
Use the new WorkQueue::postIfOpen() method in LLImageGLThread::post(). That
makes the LLImageGLThread method a trivial wrapper, which can accept templated
work items and pass them through to the WorkQueue method, eliminating double
indirection due to multiple layers of std::function.
Eliminate LLImageGLThread's WorkQueue intended for work on the main queue.
Since the main loop already has a WorkQueue of its own, post work directly to
that WorkQueue instead of using a separate WorkQueue misleadingly embedded in
LLImageGLThread.
Instead of looking up the main thread's WorkQueue every time, capture a
pointer in LLImageGL's constructor.
We no longer need a fallback queue for when the main thread's WorkQueue is
full. We no longer need the main loop to poll LLImageGL to service the local
main-thread-targeted WorkQueue, or to copy work from the fallback queue to the
main queue. That eliminates LLImageGLThread::postCallback(), mCallbackQueue,
mPendingCallbackQ, executeCallbacks() -- and even LLImageGL::updateClass() and
LLAppViewer's call to it.
Change LLViewerFetchedTexture::scheduleCreateTexture() to post work to the
main thread's WorkQueue instead of calling LLImageGLThread::postCallback().
Diffstat (limited to 'indra/llrender')
-rw-r--r-- | indra/llrender/llimagegl.cpp | 69 | ||||
-rw-r--r-- | indra/llrender/llimagegl.h | 18 |
2 files changed, 12 insertions, 75 deletions
diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp index cbc5392882..71c48801ac 100644 --- a/indra/llrender/llimagegl.cpp +++ b/indra/llrender/llimagegl.cpp @@ -183,13 +183,6 @@ void LLImageGL::initClass(LLWindow* window, S32 num_catagories, BOOL skip_analyz LLImageGLThread::sInstance->start(); } -//static -void LLImageGL::updateClass() -{ - LL_PROFILE_ZONE_SCOPED; - LLImageGLThread::sInstance->executeCallbacks(); -} - //static void LLImageGL::cleanupClass() { @@ -504,6 +497,9 @@ void LLImageGL::init(BOOL usemipmaps) #endif mCategory = -1; + + // Sometimes we have to post work for the main thread. + mMainQueue = LL::WorkQueue::getInstance("mainloop"); } void LLImageGL::cleanup() @@ -1554,7 +1550,9 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, BOOL data_ } ref(); - LLImageGLThread::sInstance->postCallback([=]() + LL::WorkQueue::postMaybe( + mMainQueue, + [=]() { LL_PROFILE_ZONE_NAMED("cglt - delete callback"); if (old_texname != 0) @@ -2266,61 +2264,6 @@ LLImageGLThread::LLImageGLThread(LLWindow* window) mContext = mWindow->createSharedContext(); } -// post a function to be executed on the LLImageGL background thread - -bool LLImageGLThread::post(const std::function<void()>& func) -{ - try - { - mFunctionQueue.post(func); - } - catch (LLThreadSafeQueueInterrupt e) - { - return false; - } - - return true; -} - -//post a callback to be executed on the main thread - -bool LLImageGLThread::postCallback(const std::function<void()>& callback) -{ - try - { - if (!mCallbackQueue.tryPost(callback)) - { - mPendingCallbackQ.push(callback); - } - } - catch (LLThreadSafeQueueInterrupt e) - { - //thread is closing, drop request - return false; - } - - return true; -} - -void LLImageGLThread::executeCallbacks() -{ - LL_PROFILE_ZONE_SCOPED; - //executed from main thread - mCallbackQueue.runPending(); - - while (!mPendingCallbackQ.empty()) - { - if (mCallbackQueue.tryPost(mPendingCallbackQ.front())) - { - mPendingCallbackQ.pop(); - } - else - { - break; - } - } -} - void LLImageGLThread::run() { mWindow->makeContextCurrent(mContext); diff --git a/indra/llrender/llimagegl.h b/indra/llrender/llimagegl.h index 8264e4a5f2..b9de481aae 100644 --- a/indra/llrender/llimagegl.h +++ b/indra/llrender/llimagegl.h @@ -198,6 +198,7 @@ private: void freePickMask(); LLPointer<LLImageRaw> mSaveData; // used for destroyGL/restoreGL + LL::WorkQueue::weak_t mMainQueue; U8* mPickMask; //downsampled bitmap approximation of alpha channel. NULL if no alpha channel U16 mPickMaskWidth; U16 mPickMaskHeight; @@ -271,7 +272,6 @@ public: public: static void initClass(LLWindow* window, S32 num_catagories, BOOL skip_analyze_alpha = false); - static void updateClass(); static void cleanupClass() ; private: @@ -313,27 +313,21 @@ public: LLImageGLThread(LLWindow* window); // post a function to be executed on the LLImageGL background thread - bool post(const std::function<void()>& func); - - //post a callback to be executed on the main thread - bool postCallback(const std::function<void()>& callback); - - void executeCallbacks(); + template <typename CALLABLE> + bool post(CALLABLE&& func) + { + return mFunctionQueue.postIfOpen(std::forward<CALLABLE>(func)); + } void run() override; // Work Queue for background thread LL::WorkQueue mFunctionQueue; - // Work Queue for main thread (run from updateClass) - LL::WorkQueue mCallbackQueue; - LLWindow* mWindow; void* mContext; LLAtomicBool mFinished; - std::queue<std::function<void()>> mPendingCallbackQ; - static LLImageGLThread* sInstance; }; |