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

Use SPSC queue in image pool workers for deep request pipelining

parent 7b046a21
No related branches found
No related tags found
No related merge requests found
...@@ -54,6 +54,11 @@ FetchContent_Declare( ...@@ -54,6 +54,11 @@ FetchContent_Declare(
GIT_REPOSITORY https://git.alchemyviewer.org/alchemy/mirrors/abseil-cpp.git GIT_REPOSITORY https://git.alchemyviewer.org/alchemy/mirrors/abseil-cpp.git
GIT_TAG 9a7e447c511dae7276ab65fde4d04f6ed52b39c9 GIT_TAG 9a7e447c511dae7276ab65fde4d04f6ed52b39c9
) )
FetchContent_Declare(
readerwriterqueue
GIT_REPOSITORY https://github.com/cameron314/readerwriterqueue
GIT_TAG v1.0.5
)
# This is a hack because absl has dumb cmake # This is a hack because absl has dumb cmake
set(OLD_BUILD_TEST ${BUILD_TESTING}) set(OLD_BUILD_TEST ${BUILD_TESTING})
...@@ -94,5 +99,7 @@ set(JSON_Install OFF CACHE INTERNAL "") ...@@ -94,5 +99,7 @@ set(JSON_Install OFF CACHE INTERNAL "")
set(JSON_BuildTests OFF CACHE INTERNAL "") set(JSON_BuildTests OFF CACHE INTERNAL "")
FetchContent_MakeAvailable(nlohmann_json) FetchContent_MakeAvailable(nlohmann_json)
FetchContent_MakeAvailable(readerwriterqueue)
unset(CMAKE_FOLDER) unset(CMAKE_FOLDER)
unset(CMAKE_POSITION_INDEPENDENT_CODE) unset(CMAKE_POSITION_INDEPENDENT_CODE)
...@@ -79,6 +79,7 @@ target_link_libraries(llimage ...@@ -79,6 +79,7 @@ target_link_libraries(llimage
${JPEG_LIBRARIES} ${JPEG_LIBRARIES}
${PNG_LIBRARIES} ${PNG_LIBRARIES}
${ZLIB_LIBRARIES} ${ZLIB_LIBRARIES}
readerwriterqueue
) )
if(${CMAKE_VERSION} VERSION_GREATER "3.15.0") if(${CMAKE_VERSION} VERSION_GREATER "3.15.0")
......
...@@ -28,54 +28,49 @@ ...@@ -28,54 +28,49 @@
#include "llimageworker.h" #include "llimageworker.h"
#include "llimagedxt.h" #include "llimagedxt.h"
#include <readerwriterqueue.h>
std::atomic< U32 > sImageThreads; std::atomic< U32 > sImageThreads;
class PoolWorkerThread : public LLThread class PoolWorkerThread : public LLThread
{ {
public: public:
PoolWorkerThread(std::string name) : LLThread(name), PoolWorkerThread(std::string name) : LLThread(name), mRequestQueue(30)
mCurrentRequest(NULL)
{ {
} }
virtual void run() virtual void run()
{ {
while (!isQuitting()) while (!isQuitting())
{ {
auto *pReq = mCurrentRequest.exchange(nullptr); checkPause();
if (pReq) LLImageDecodeThread::ImageRequest* req = nullptr;
pReq->processRequestIntern(); while (!isQuitting() && mRequestQueue.try_dequeue(req))
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 mCurrentRequest != NULL; return mRequestQueue.size_approx() > 0;
} }
bool setRequest(LLImageDecodeThread::ImageRequest* req) bool setRequest(LLImageDecodeThread::ImageRequest* req)
{ {
LLImageDecodeThread::ImageRequest* pOld{ nullptr }; bool bSuccess = mRequestQueue.try_enqueue(req);
bool bSuccess = mCurrentRequest.compare_exchange_strong(pOld, req);
wake(); wake();
return bSuccess; return bSuccess;
} }
private: private:
std::atomic< LLImageDecodeThread::ImageRequest * > mCurrentRequest; moodycamel::ReaderWriterQueue<LLImageDecodeThread::ImageRequest*> mRequestQueue;
}; };
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
...@@ -344,7 +339,7 @@ bool LLImageDecodeThread::enqueRequest(ImageRequest * req) ...@@ -344,7 +339,7 @@ bool LLImageDecodeThread::enqueRequest(ImageRequest * req)
mLastPoolAllocation = 0; mLastPoolAllocation = 0;
} }
auto& thread = mThreadPool[mLastPoolAllocation++]; auto& thread = mThreadPool[mLastPoolAllocation++];
if (!thread->isBusy() && thread->setRequest(req)) if (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