summaryrefslogtreecommitdiff
path: root/thirdparty/etcpak/TaskDispatch.hpp
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-04-13 01:09:38 +0200
committerGitHub <noreply@github.com>2021-04-13 01:09:38 +0200
commit8793a464d312c5a48490fbec03c26f2835318063 (patch)
tree8be39ad26992b0bc10ee69fef5f0c5cadb6a0760 /thirdparty/etcpak/TaskDispatch.hpp
parent075f358fcddbb3df8417ef85baabdf3684a4efd2 (diff)
parentd840165a324b5c218ca3a4882f030986855c8383 (diff)
Merge pull request #47370 from fire/etcpak
Add thirdparty library etcpak for faster imports.
Diffstat (limited to 'thirdparty/etcpak/TaskDispatch.hpp')
-rw-r--r--thirdparty/etcpak/TaskDispatch.hpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/thirdparty/etcpak/TaskDispatch.hpp b/thirdparty/etcpak/TaskDispatch.hpp
new file mode 100644
index 0000000000..b513de4c0c
--- /dev/null
+++ b/thirdparty/etcpak/TaskDispatch.hpp
@@ -0,0 +1,34 @@
+#ifndef __DARKRL__TASKDISPATCH_HPP__
+#define __DARKRL__TASKDISPATCH_HPP__
+
+#include <atomic>
+#include <condition_variable>
+#include <functional>
+#include <mutex>
+#include <thread>
+#include <vector>
+
+class TaskDispatch
+{
+public:
+ TaskDispatch( size_t workers );
+ ~TaskDispatch();
+
+ static void Queue( const std::function<void(void)>& f );
+ static void Queue( std::function<void(void)>&& f );
+
+ static void Sync();
+
+private:
+ void Worker();
+
+ std::vector<std::function<void(void)>> m_queue;
+ std::mutex m_queueLock;
+ std::condition_variable m_cvWork, m_cvJobs;
+ std::atomic<bool> m_exit;
+ size_t m_jobs;
+
+ std::vector<std::thread> m_workers;
+};
+
+#endif