summaryrefslogtreecommitdiffstats
path: root/src/common/thread_worker.cpp
diff options
context:
space:
mode:
authorReinUsesLisp <reinuseslisp@airmail.cc>2021-05-26 01:37:06 +0200
committerReinUsesLisp <reinuseslisp@airmail.cc>2021-07-09 00:03:26 +0200
commitda34d3704405665b68d3d992f37a7eeb541238af (patch)
tree69ac607431b72f5088c6d57a0348cedb5fdcb835 /src/common/thread_worker.cpp
parentcommon/thread_worker: Simplify logic (diff)
downloadyuzu-da34d3704405665b68d3d992f37a7eeb541238af.tar
yuzu-da34d3704405665b68d3d992f37a7eeb541238af.tar.gz
yuzu-da34d3704405665b68d3d992f37a7eeb541238af.tar.bz2
yuzu-da34d3704405665b68d3d992f37a7eeb541238af.tar.lz
yuzu-da34d3704405665b68d3d992f37a7eeb541238af.tar.xz
yuzu-da34d3704405665b68d3d992f37a7eeb541238af.tar.zst
yuzu-da34d3704405665b68d3d992f37a7eeb541238af.zip
Diffstat (limited to 'src/common/thread_worker.cpp')
-rw-r--r--src/common/thread_worker.cpp66
1 files changed, 0 insertions, 66 deletions
diff --git a/src/common/thread_worker.cpp b/src/common/thread_worker.cpp
deleted file mode 100644
index 32be49b15..000000000
--- a/src/common/thread_worker.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright 2020 yuzu emulator team
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#include "common/thread.h"
-#include "common/thread_worker.h"
-
-namespace Common {
-
-ThreadWorker::ThreadWorker(std::size_t num_workers, const std::string& name) {
- workers_queued.store(static_cast<u64>(num_workers), std::memory_order_release);
- const auto lambda = [this, thread_name{std::string{name}}] {
- Common::SetCurrentThreadName(thread_name.c_str());
-
- while (!stop) {
- UniqueFunction<void> task;
- {
- std::unique_lock lock{queue_mutex};
- if (requests.empty()) {
- wait_condition.notify_all();
- }
- condition.wait(lock, [this] { return stop || !requests.empty(); });
- if (stop) {
- break;
- }
- task = std::move(requests.front());
- requests.pop();
- }
- task();
- work_done++;
- }
- workers_stopped++;
- wait_condition.notify_all();
- };
- for (size_t i = 0; i < num_workers; ++i) {
- threads.emplace_back(lambda);
- }
-}
-
-ThreadWorker::~ThreadWorker() {
- {
- std::unique_lock lock{queue_mutex};
- stop = true;
- }
- condition.notify_all();
- for (std::thread& thread : threads) {
- thread.join();
- }
-}
-
-void ThreadWorker::QueueWork(UniqueFunction<void> work) {
- {
- std::unique_lock lock{queue_mutex};
- requests.emplace(std::move(work));
- work_scheduled++;
- }
- condition.notify_one();
-}
-
-void ThreadWorker::WaitForRequests() {
- std::unique_lock lock{queue_mutex};
- wait_condition.wait(
- lock, [this] { return workers_stopped >= workers_queued || work_done >= work_scheduled; });
-}
-
-} // namespace Common