From: sapier Date: Wed, 13 Nov 2013 20:46:14 +0000 (+0100) Subject: Fix multicaller support in RequestQueue X-Git-Tag: 0.4.8~34 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=dc407e219f8b0394f3a4d10ea8379b8678d98d1c;p=oweals%2Fminetest.git Fix multicaller support in RequestQueue --- diff --git a/src/itemdef.cpp b/src/itemdef.cpp index 83a70f1d7..c520ea902 100644 --- a/src/itemdef.cpp +++ b/src/itemdef.cpp @@ -638,12 +638,9 @@ public: { GetRequest request = m_get_clientcached_queue.pop(); - GetResult - result; - result.key = request.key; - result.callers = request.callers; - result.item = createClientCachedDirect(request.key, gamedef); - request.dest->push_back(result); + + m_get_clientcached_queue.pushResult(request, + createClientCachedDirect(request.key, gamedef)); } #endif } diff --git a/src/shader.cpp b/src/shader.cpp index ed8cc5b73..122cbea19 100644 --- a/src/shader.cpp +++ b/src/shader.cpp @@ -546,13 +546,7 @@ void ShaderSource::processQueue() <<"name=\""< - result; - result.key = request.key; - result.callers = request.callers; - result.item = getShaderIdDirect(request.key); - - request.dest->push_back(result); + m_get_shader_queue.pushResult(request,getShaderIdDirect(request.key)); } } diff --git a/src/tile.cpp b/src/tile.cpp index 3c4989ea8..5dec79a10 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -786,13 +786,7 @@ void TextureSource::processQueue() <<"name=\""< - result; - result.key = request.key; - result.callers = request.callers; - result.item = getTextureIdDirect(request.key); - - request.dest->push_back(result); + m_get_texture_queue.pushResult(request,getTextureIdDirect(request.key)); } } diff --git a/src/util/thread.h b/src/util/thread.h index 678d9cf9b..70d41aeb9 100644 --- a/src/util/thread.h +++ b/src/util/thread.h @@ -106,13 +106,7 @@ public: A single worker thread - multiple client threads queue framework. */ -template -class CallerInfo -{ -public: - Caller caller; - Data data; -}; + template class GetResult @@ -120,7 +114,7 @@ class GetResult public: Key key; T item; - std::list > callers; + std::pair caller; }; template @@ -128,22 +122,24 @@ class ResultQueue: public MutexedQueue< GetResult > { }; +template +class CallerInfo +{ +public: + Caller caller; + Data data; + ResultQueue< Key, T, Caller, Data>* dest; +}; + template class GetRequest { public: GetRequest() { - dest = NULL; - } - GetRequest(ResultQueue *a_dest) - { - dest = a_dest; } - GetRequest(ResultQueue *a_dest, - Key a_key) + GetRequest(Key a_key) { - dest = a_dest; key = a_key; } ~GetRequest() @@ -151,8 +147,7 @@ public: } Key key; - ResultQueue *dest; - std::list > callers; + std::list > callers; }; template @@ -180,20 +175,21 @@ public: if(request.key == key) { - for(typename std::list< CallerInfo >::iterator + for(typename std::list< CallerInfo >::iterator i = request.callers.begin(); i != request.callers.end(); ++i) { - CallerInfo &ca = *i; + CallerInfo &ca = *i; if(ca.caller == caller) { ca.data = callerdata; return; } } - CallerInfo ca; + CallerInfo ca; ca.caller = caller; ca.data = callerdata; + ca.dest = dest; request.callers.push_back(ca); return; } @@ -205,11 +201,11 @@ public: GetRequest request; request.key = key; - CallerInfo ca; + CallerInfo ca; ca.caller = caller; ca.data = callerdata; + ca.dest = dest; request.callers.push_back(ca); - request.dest = dest; m_queue.getList().push_back(request); } @@ -219,6 +215,26 @@ public: return m_queue.pop_front(wait_if_empty); } + void pushResult(GetRequest req, + T res) { + + for(typename std::list< CallerInfo >::iterator + i = req.callers.begin(); + i != req.callers.end(); ++i) + { + CallerInfo &ca = *i; + + GetResult result; + + result.key = req.key; + result.item = res; + result.caller.first = ca.caller; + result.caller.second = ca.data; + + ca.dest->push_back(result); + } + } + private: MutexedQueue< GetRequest > m_queue; };