From 8b0b857eaaa50c6ec217a46c0577395c78ec04c7 Mon Sep 17 00:00:00 2001 From: sapier Date: Mon, 6 Jan 2014 12:45:42 +0100 Subject: Make MutexQueue use jsemaphore for signaling --- src/util/thread.h | 62 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 27 deletions(-) (limited to 'src/util/thread.h') diff --git a/src/util/thread.h b/src/util/thread.h index bb8e03317..8b3c33621 100644 --- a/src/util/thread.h +++ b/src/util/thread.h @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "../jthread/jthread.h" #include "../jthread/jmutex.h" #include "../jthread/jmutexautolock.h" +#include "porting.h" template class MutexedVariable @@ -123,36 +124,38 @@ public: void add(Key key, Caller caller, CallerData callerdata, ResultQueue *dest) { - JMutexAutoLock lock(m_queue.getMutex()); - - /* - If the caller is already on the list, only update CallerData - */ - for(typename std::list< GetRequest >::iterator - i = m_queue.getList().begin(); - i != m_queue.getList().end(); ++i) { - GetRequest &request = *i; - - if(request.key == key) + JMutexAutoLock lock(m_queue.getMutex()); + + /* + If the caller is already on the list, only update CallerData + */ + for(typename std::list< GetRequest >::iterator + i = m_queue.getList().begin(); + i != m_queue.getList().end(); ++i) { - for(typename std::list< CallerInfo >::iterator - i = request.callers.begin(); - i != request.callers.end(); ++i) + GetRequest &request = *i; + + if(request.key == key) { - CallerInfo &ca = *i; - if(ca.caller == caller) + for(typename std::list< CallerInfo >::iterator + i = request.callers.begin(); + i != request.callers.end(); ++i) { - ca.data = callerdata; - return; + CallerInfo &ca = *i; + if(ca.caller == caller) + { + ca.data = callerdata; + return; + } } + CallerInfo ca; + ca.caller = caller; + ca.data = callerdata; + ca.dest = dest; + request.callers.push_back(ca); + return; } - CallerInfo ca; - ca.caller = caller; - ca.data = callerdata; - ca.dest = dest; - request.callers.push_back(ca); - return; } } @@ -168,12 +171,17 @@ public: ca.dest = dest; request.callers.push_back(ca); - m_queue.getList().push_back(request); + m_queue.push_back(request); + } + + GetRequest pop(unsigned int timeout_ms) + { + return m_queue.pop_front(timeout_ms); } - GetRequest pop(bool wait_if_empty=false) + GetRequest pop() { - return m_queue.pop_front(wait_if_empty); + return m_queue.pop_frontNoEx(); } void pushResult(GetRequest req, -- cgit v1.2.3