From aaeb8a24150f2c40f02c0a90eeaf4e64aa323618 Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Sun, 5 Feb 2023 14:04:33 -0500
Subject: [PATCH] Revert "Tweak texture decode thread behavior to not choke"

This reverts commit 22d62720e839e9044385133059e09e369ac04162.
---
 indra/llimage/llimageworker.cpp | 45 +++++++++++++++------------------
 1 file changed, 20 insertions(+), 25 deletions(-)

diff --git a/indra/llimage/llimageworker.cpp b/indra/llimage/llimageworker.cpp
index 97119bb9e8a..c8700fc793c 100644
--- a/indra/llimage/llimageworker.cpp
+++ b/indra/llimage/llimageworker.cpp
@@ -35,8 +35,7 @@ std::atomic< U32 > sImageThreads = 0;
 class PoolWorkerThread final : public LLThread
 {
 public:
-	PoolWorkerThread(std::string name) : LLThread(name),
-		mCurrentRequest(NULL)
+	PoolWorkerThread(std::string name) : LLThread(name), mRequestQueue(512)
 	{
 	}
 
@@ -44,40 +43,36 @@ class PoolWorkerThread final : public LLThread
 	{
 		while (!isQuitting())
 		{
-			auto *pReq = mCurrentRequest.exchange(nullptr);
-
-			if (pReq)
-				pReq->processRequestIntern();
-			checkPause();
+            checkPause();
+
+			LLImageDecodeThread::ImageRequest* req  = nullptr;
+            while (!isQuitting() && mRequestQueue.tryPop(req))
+            {
+                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()
-	{
-		return mCurrentRequest != NULL;
+    {
+        return mRequestQueue.size() > 0;
 	}
 
 	bool setRequest(LLImageDecodeThread::ImageRequest* req)
 	{
-		LLImageDecodeThread::ImageRequest* pOld{ nullptr };
-		bool bSuccess = mCurrentRequest.compare_exchange_strong(pOld, req);
-		wake();
-
+        bool bSuccess = mRequestQueue.tryPush(req);
+		if(bSuccess)
+		{
+		    wake();
+		}
 		return bSuccess;
 	}
 
 private:
-	std::atomic<LLImageDecodeThread::ImageRequest*> mCurrentRequest;
+	LLThreadSafeQueue<LLImageDecodeThread::ImageRequest*> mRequestQueue;
 };
 
 //----------------------------------------------------------------------------
@@ -356,7 +351,7 @@ bool LLImageDecodeThread::enqueRequest(ImageRequest * req)
             mLastPoolAllocation = 0;
         }
         auto& thread = mThreadPool[mLastPoolAllocation++];
-        if (!thread->isBusy() && thread->setRequest(req))
+        if (thread->setRequest(req))
         {
             return true;
         }
-- 
GitLab