summaryrefslogtreecommitdiffstats
path: root/src/ThreadsafeQueue.h
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2014-03-23 14:10:45 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2014-03-23 14:10:45 +0100
commite3f85ddc8ea565bc81b538269298a9f97b055c8c (patch)
tree34b8c42021261bbb4e6cbc0b9d94e59ce834ee08 /src/ThreadsafeQueue.h
parent8048e2e242c6029337bfe6cc056d2830b127044b (diff)
downloaddabmod-e3f85ddc8ea565bc81b538269298a9f97b055c8c.tar.gz
dabmod-e3f85ddc8ea565bc81b538269298a9f97b055c8c.tar.bz2
dabmod-e3f85ddc8ea565bc81b538269298a9f97b055c8c.zip
Fix livelock in synchronous ZeroMQ scenario
Diffstat (limited to 'src/ThreadsafeQueue.h')
-rw-r--r--src/ThreadsafeQueue.h11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/ThreadsafeQueue.h b/src/ThreadsafeQueue.h
index 3dd5450..78e9ef0 100644
--- a/src/ThreadsafeQueue.h
+++ b/src/ThreadsafeQueue.h
@@ -54,7 +54,8 @@ public:
/* Create a queue where it has to contain at least
* required_size elements before pop is possible
*/
- ThreadsafeQueue(size_t required_size) : the_required_size(required_size) {}
+ ThreadsafeQueue(size_t required_size) : the_required_size(required_size) {
+ }
/* Push one element into the queue, and notify another thread that
* might be waiting.
@@ -84,6 +85,11 @@ public:
return the_queue.empty();
}
+ size_t size() const
+ {
+ return the_queue.size();
+ }
+
bool try_pop(T& popped_value)
{
boost::mutex::scoped_lock lock(the_mutex);
@@ -100,8 +106,7 @@ public:
void wait_and_pop(T& popped_value)
{
boost::mutex::scoped_lock lock(the_mutex);
- while(the_queue.size() < the_required_size)
- {
+ while(the_queue.size() < the_required_size) {
the_condition_variable.wait(lock);
}