summaryrefslogtreecommitdiff
path: root/indra/llrender
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llrender')
-rw-r--r--indra/llrender/llimagegl.cpp89
-rw-r--r--indra/llrender/llimagegl.h27
2 files changed, 24 insertions, 92 deletions
diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp
index ed0e3fb345..894eb8c773 100644
--- a/indra/llrender/llimagegl.cpp
+++ b/indra/llrender/llimagegl.cpp
@@ -172,31 +172,19 @@ BOOL is_little_endian()
return (*c == 0x78) ;
}
-LLImageGLThread* LLImageGLThread::sInstance = nullptr;
-
//static
void LLImageGL::initClass(LLWindow* window, S32 num_catagories, BOOL skip_analyze_alpha /* = false */)
{
LL_PROFILE_ZONE_SCOPED;
sSkipAnalyzeAlpha = skip_analyze_alpha;
- LLImageGLThread::sInstance = new LLImageGLThread(window);
- LLImageGLThread::sInstance->start();
-}
-
-//static
-void LLImageGL::updateClass()
-{
- LL_PROFILE_ZONE_SCOPED;
- LLImageGLThread::sInstance->executeCallbacks();
+ LLImageGLThread::createInstance(window);
}
//static
void LLImageGL::cleanupClass()
{
LL_PROFILE_ZONE_SCOPED;
- LLImageGLThread::sInstance->mFunctionQueue.close();
- delete LLImageGLThread::sInstance;
- LLImageGLThread::sInstance = nullptr;
+ LLImageGLThread::deleteSingleton();
}
//static
@@ -504,6 +492,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()
@@ -1536,8 +1527,7 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, BOOL data_
}
//if we're on the image loading thread, be sure to delete old_texname and update mTexName on the main thread
- if (LLImageGLThread::sInstance != nullptr &&
- LLThread::currentID() == LLImageGLThread::sInstance->getID())
+ if (! on_main_thread())
{
{
LL_PROFILE_ZONE_NAMED("cglt - sync");
@@ -1554,7 +1544,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)
@@ -2259,7 +2251,11 @@ void LLImageGL::resetCurTexSizebar()
*/
LLImageGLThread::LLImageGLThread(LLWindow* window)
- : LLThread("LLImageGL"), mWindow(window)
+ // We want exactly one thread, but a very large capacity: we never want
+ // anyone, especially inner-loop render code, to have to block on post()
+ // because we're full.
+ : ThreadPool("LLImageGL", 1, 1024*1024)
+ , mWindow(window)
{
LL_PROFILE_ZONE_SCOPED;
mFinished = false;
@@ -2268,61 +2264,6 @@ LLImageGLThread::LLImageGLThread(LLWindow* window)
ThreadPool::start();
}
-// 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()
{
LL_PROFILE_ZONE_SCOPED;
@@ -2330,7 +2271,7 @@ void LLImageGLThread::run()
// WorkQueue, likewise cleanup afterwards.
mWindow->makeContextCurrent(mContext);
gGL.init();
- mFunctionQueue.runUntilClose();
+ ThreadPool::run();
gGL.shutdown();
mWindow->destroySharedContext(mContext);
}
diff --git a/indra/llrender/llimagegl.h b/indra/llrender/llimagegl.h
index bb46dbc639..ae773bb362 100644
--- a/indra/llrender/llimagegl.h
+++ b/indra/llrender/llimagegl.h
@@ -37,6 +37,7 @@
#include "llunits.h"
#include "llthreadsafequeue.h"
#include "llrender.h"
+#include "threadpool.h"
#include "workqueue.h"
class LLTextureAtlas ;
@@ -198,6 +199,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 +273,6 @@ public:
public:
static void initClass(LLWindow* window, S32 num_catagories, BOOL skip_analyze_alpha = false);
- static void updateClass();
static void cleanupClass() ;
private:
@@ -307,34 +308,24 @@ public:
};
-class LLImageGLThread : public LLThread
+class LLImageGLThread : public LLSimpleton<LLImageGLThread>, LL::ThreadPool
{
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 getQueue().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;
-
+private:
LLWindow* mWindow;
void* mContext = nullptr;
LLAtomicBool mFinished;
-
- std::queue<std::function<void()>> mPendingCallbackQ;
-
- static LLImageGLThread* sInstance;
};