summaryrefslogtreecommitdiff
path: root/src/common/thread_worker.h
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2020-12-30 22:06:05 -0800
committerGitHub <noreply@github.com>2020-12-30 22:06:05 -0800
commit25d607f5f63929369fb74f386a920b69bb24f442 (patch)
tree9ee5a023f033d99561a0358c5c71aeecc92c9d64 /src/common/thread_worker.h
parent53e49e536004eb983fbd3acea96ad57e3c3f7d4b (diff)
parent82e0eeed21d34accb5f69f7436b2d525b701e68e (diff)
Merge pull request #5208 from bunnei/service-threads
Service threads
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