summaryrefslogtreecommitdiff
path: root/osdep/BlockingQueue.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'osdep/BlockingQueue.hpp')
-rw-r--r--osdep/BlockingQueue.hpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/osdep/BlockingQueue.hpp b/osdep/BlockingQueue.hpp
index 351a095a..03986efe 100644
--- a/osdep/BlockingQueue.hpp
+++ b/osdep/BlockingQueue.hpp
@@ -32,6 +32,8 @@
#include <condition_variable>
#include <chrono>
+#include "Thread.hpp"
+
namespace ZeroTier {
/**
@@ -52,6 +54,23 @@ public:
c.notify_one();
}
+ inline void postWait(T t,unsigned long maxQueueSize)
+ {
+ for(;;) {
+ {
+ std::lock_guard<std::mutex> lock(m);
+ if (q.size() < maxQueueSize) {
+ q.push(t);
+ c.notify_one();
+ return;
+ }
+ }
+ if (!r)
+ break;
+ Thread::sleep(1);
+ }
+ }
+
inline void stop(void)
{
std::lock_guard<std::mutex> lock(m);
@@ -98,8 +117,8 @@ public:
private:
volatile bool r;
std::queue<T> q;
- std::mutex m;
- std::condition_variable c;
+ mutable std::mutex m;
+ mutable std::condition_variable c;
};
} // namespace ZeroTier