aboutsummaryrefslogtreecommitdiff
path: root/src/util/thread.h
diff options
context:
space:
mode:
authorsapier <Sapier at GMX dot net>2014-01-06 12:45:42 +0100
committersapier <Sapier at GMX dot net>2014-01-10 10:10:45 +0100
commit8b0b857eaaa50c6ec217a46c0577395c78ec04c7 (patch)
treeb9fd5e1edb099aee1498b29a43702568a283aa34 /src/util/thread.h
parent10fdbf737513e48bfcfb9e90fe243dcd989c0476 (diff)
downloadminetest-8b0b857eaaa50c6ec217a46c0577395c78ec04c7.tar.gz
minetest-8b0b857eaaa50c6ec217a46c0577395c78ec04c7.tar.bz2
minetest-8b0b857eaaa50c6ec217a46c0577395c78ec04c7.zip
Make MutexQueue use jsemaphore for signaling
Diffstat (limited to 'src/util/thread.h')
-rw-r--r--src/util/thread.h62
1 files changed, 35 insertions, 27 deletions
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<typename T>
class MutexedVariable
@@ -123,36 +124,38 @@ public:
void add(Key key, Caller caller, CallerData callerdata,
ResultQueue<Key, T, Caller, CallerData> *dest)
{
- JMutexAutoLock lock(m_queue.getMutex());
-
- /*
- If the caller is already on the list, only update CallerData
- */
- for(typename std::list< GetRequest<Key, T, Caller, CallerData> >::iterator
- i = m_queue.getList().begin();
- i != m_queue.getList().end(); ++i)
{
- GetRequest<Key, T, Caller, CallerData> &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<Key, T, Caller, CallerData> >::iterator
+ i = m_queue.getList().begin();
+ i != m_queue.getList().end(); ++i)
{
- for(typename std::list< CallerInfo<Caller, CallerData, Key, T> >::iterator
- i = request.callers.begin();
- i != request.callers.end(); ++i)
+ GetRequest<Key, T, Caller, CallerData> &request = *i;
+
+ if(request.key == key)
{
- CallerInfo<Caller, CallerData, Key, T> &ca = *i;
- if(ca.caller == caller)
+ for(typename std::list< CallerInfo<Caller, CallerData, Key, T> >::iterator
+ i = request.callers.begin();
+ i != request.callers.end(); ++i)
{
- ca.data = callerdata;
- return;
+ CallerInfo<Caller, CallerData, Key, T> &ca = *i;
+ if(ca.caller == caller)
+ {
+ ca.data = callerdata;
+ return;
+ }
}
+ CallerInfo<Caller, CallerData, Key, T> ca;
+ ca.caller = caller;
+ ca.data = callerdata;
+ ca.dest = dest;
+ request.callers.push_back(ca);
+ return;
}
- CallerInfo<Caller, CallerData, Key, T> 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<Key, T, Caller, CallerData> pop(unsigned int timeout_ms)
+ {
+ return m_queue.pop_front(timeout_ms);
}
- GetRequest<Key, T, Caller, CallerData> pop(bool wait_if_empty=false)
+ GetRequest<Key, T, Caller, CallerData> pop()
{
- return m_queue.pop_front(wait_if_empty);
+ return m_queue.pop_frontNoEx();
}
void pushResult(GetRequest<Key, T, Caller, CallerData> req,