summaryrefslogtreecommitdiff
path: root/osdep
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2018-11-13 12:07:58 -0800
committerAdam Ierymenko <adam.ierymenko@gmail.com>2018-11-13 12:07:58 -0800
commit90631adb9beda188bd00494f1a84446c0b94d0f9 (patch)
treef5e6cb3a2edff81fc12c93fe1d800efacddc818a /osdep
parentf6450cd7e14bc15ea7361a4f9e8e9a09fa15228d (diff)
downloadinfinitytier-90631adb9beda188bd00494f1a84446c0b94d0f9.tar.gz
infinitytier-90631adb9beda188bd00494f1a84446c0b94d0f9.zip
Improve multithreading support for OneService (faster, dynamic adjustment of thread count based on HW concurrency).
Diffstat (limited to 'osdep')
-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