Skip to content
Snippets Groups Projects
Commit 22d62720 authored by Rye Mutt's avatar Rye Mutt :bread:
Browse files

Tweak texture decode thread behavior to not choke

parent 14e8ad1c
No related branches found
No related tags found
No related merge requests found
...@@ -35,7 +35,8 @@ std::atomic< U32 > sImageThreads = 0; ...@@ -35,7 +35,8 @@ std::atomic< U32 > sImageThreads = 0;
class PoolWorkerThread final : public LLThread class PoolWorkerThread final : public LLThread
{ {
public: public:
PoolWorkerThread(std::string name) : LLThread(name), mRequestQueue(256) PoolWorkerThread(std::string name) : LLThread(name),
mCurrentRequest(NULL)
{ {
} }
...@@ -43,36 +44,40 @@ class PoolWorkerThread final : public LLThread ...@@ -43,36 +44,40 @@ class PoolWorkerThread final : public LLThread
{ {
while (!isQuitting()) while (!isQuitting())
{ {
checkPause(); auto *pReq = mCurrentRequest.exchange(nullptr);
LLImageDecodeThread::ImageRequest* req = nullptr; if (pReq)
while (!isQuitting() && mRequestQueue.tryPop(req)) pReq->processRequestIntern();
{ checkPause();
if (req)
{
req->processRequestIntern();
}
}
} }
} }
bool isBusy()
{
auto *pReq = mCurrentRequest.load();
if (!pReq)
return false;
auto status = pReq->getStatus();
return status == LLQueuedThread::STATUS_QUEUED || status == LLQueuedThread::STATUS_INPROGRESS;
}
bool runCondition() bool runCondition()
{ {
return mRequestQueue.size() > 0; return mCurrentRequest != NULL;
} }
bool setRequest(LLImageDecodeThread::ImageRequest* req) bool setRequest(LLImageDecodeThread::ImageRequest* req)
{ {
bool bSuccess = mRequestQueue.tryPush(req); LLImageDecodeThread::ImageRequest* pOld{ nullptr };
if(bSuccess) bool bSuccess = mCurrentRequest.compare_exchange_strong(pOld, req);
{ wake();
wake();
}
return bSuccess; return bSuccess;
} }
private: private:
LLThreadSafeQueue<LLImageDecodeThread::ImageRequest*> mRequestQueue; std::atomic<LLImageDecodeThread::ImageRequest*> mCurrentRequest;
}; };
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
...@@ -344,13 +349,14 @@ bool LLImageDecodeThread::ImageRequest::tut_isOK() ...@@ -344,13 +349,14 @@ bool LLImageDecodeThread::ImageRequest::tut_isOK()
bool LLImageDecodeThread::enqueRequest(ImageRequest * req) bool LLImageDecodeThread::enqueRequest(ImageRequest * req)
{ {
for(size_t num_tries = 0, pool_size = mThreadPool.size(); num_tries < pool_size; ++num_tries)
{ {
if (mLastPoolAllocation >= mThreadPool.size()) if (mLastPoolAllocation >= pool_size)
{ {
mLastPoolAllocation = 0; mLastPoolAllocation = 0;
} }
auto& thread = mThreadPool[mLastPoolAllocation++]; auto& thread = mThreadPool[mLastPoolAllocation++];
if (thread->setRequest(req)) if (!thread->isBusy() && thread->setRequest(req))
{ {
return true; return true;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment