summaryrefslogtreecommitdiff
path: root/src/common/thread_worker.h
diff options
context:
space:
mode:
authorLevi <L3ehunin@gmail.com>2021-01-10 22:09:56 -0700
committerLevi <L3ehunin@gmail.com>2021-01-10 22:09:56 -0700
commit7a3c884e39fccfbb498b855080bffabc9ce2e7f1 (patch)
tree5056f9406dec188439cb0deb87603498243a9412 /src/common/thread_worker.h
parentbc69cc151192326f9b8e18bbda831f1589ba27e0 (diff)
parent46cd71d1c773c29cce8b48e7e2b478bdf6d77085 (diff)
Merge remote-tracking branch 'upstream/master' into int-flags
Diffstat (limited to 'src/common/thread_worker.h')
-rw-r--r--src/common/thread_worker.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/common/thread_worker.h b/src/common/thread_worker.h
new file mode 100644
index 000000000..f1859971f
--- /dev/null
+++ b/src/common/thread_worker.h
@@ -0,0 +1,30 @@
+// Copyright 2020 yuzu emulator team
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <atomic>
+#include <functional>
+#include <mutex>
+#include <string>
+#include <vector>
+#include <queue>
+
+namespace Common {
+
+class ThreadWorker final {
+public:
+ explicit ThreadWorker(std::size_t num_workers, const std::string& name);
+ ~ThreadWorker();
+ void QueueWork(std::function<void()>&& work);
+
+private:
+ std::vector<std::thread> threads;
+ std::queue<std::function<void()>> requests;
+ std::mutex queue_mutex;
+ std::condition_variable condition;
+ std::atomic_bool stop{};
+};
+
+} // namespace Common