aboutsummaryrefslogtreecommitdiff
path: root/src/common/thread_worker.h
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2020-12-29 16:36:35 -0800
committerbunnei <bunneidev@gmail.com>2020-12-29 16:46:29 -0800
commit69e82d01d5012c0078f65a294ecbb7118707f73c (patch)
treed8bac45fa91904abec67a0d76c29e4f7e3aeaab8 /src/common/thread_worker.h
parentc192da3f82ea3b2563ce43a340c88ac9a6602f26 (diff)
common: ThreadWorker: Add class to help do asynchronous work.
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 0000000000..f1859971fc
--- /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