diff options
author | bunnei <bunneidev@gmail.com> | 2021-12-13 07:43:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-13 07:43:25 +0100 |
commit | 280c77989880e81f622440b157a0ce1b7139847b (patch) | |
tree | 49a3ef8127d721dc44effb8315e5db7e796336f4 /src/core/hle/kernel/service_thread.cpp | |
parent | Merge pull request #7495 from FernandoS27/text-blit-fix-again (diff) | |
parent | hle: kernel k_scheduler: EnableScheduling: Remove redundant GetCurrentThreadPointer calls. (diff) | |
download | yuzu-280c77989880e81f622440b157a0ce1b7139847b.tar yuzu-280c77989880e81f622440b157a0ce1b7139847b.tar.gz yuzu-280c77989880e81f622440b157a0ce1b7139847b.tar.bz2 yuzu-280c77989880e81f622440b157a0ce1b7139847b.tar.lz yuzu-280c77989880e81f622440b157a0ce1b7139847b.tar.xz yuzu-280c77989880e81f622440b157a0ce1b7139847b.tar.zst yuzu-280c77989880e81f622440b157a0ce1b7139847b.zip |
Diffstat (limited to '')
-rw-r--r-- | src/core/hle/kernel/service_thread.cpp | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/src/core/hle/kernel/service_thread.cpp b/src/core/hle/kernel/service_thread.cpp index 6721b6276..03f3dec10 100644 --- a/src/core/hle/kernel/service_thread.cpp +++ b/src/core/hle/kernel/service_thread.cpp @@ -25,24 +25,27 @@ public: void QueueSyncRequest(KSession& session, std::shared_ptr<HLERequestContext>&& context); private: - std::vector<std::thread> threads; + std::vector<std::jthread> threads; std::queue<std::function<void()>> requests; std::mutex queue_mutex; - std::condition_variable condition; + std::condition_variable_any condition; const std::string service_name; - bool stop{}; }; ServiceThread::Impl::Impl(KernelCore& kernel, std::size_t num_threads, const std::string& name) : service_name{name} { - for (std::size_t i = 0; i < num_threads; ++i) - threads.emplace_back([this, &kernel] { + for (std::size_t i = 0; i < num_threads; ++i) { + threads.emplace_back([this, &kernel](std::stop_token stop_token) { Common::SetCurrentThreadName(std::string{"yuzu:HleService:" + service_name}.c_str()); // Wait for first request before trying to acquire a render context { std::unique_lock lock{queue_mutex}; - condition.wait(lock, [this] { return stop || !requests.empty(); }); + condition.wait(lock, stop_token, [this] { return !requests.empty(); }); + } + + if (stop_token.stop_requested()) { + return; } kernel.RegisterHostThread(); @@ -52,10 +55,16 @@ ServiceThread::Impl::Impl(KernelCore& kernel, std::size_t num_threads, const std { std::unique_lock lock{queue_mutex}; - condition.wait(lock, [this] { return stop || !requests.empty(); }); - if (stop || requests.empty()) { + condition.wait(lock, stop_token, [this] { return !requests.empty(); }); + + if (stop_token.stop_requested()) { return; } + + if (requests.empty()) { + continue; + } + task = std::move(requests.front()); requests.pop(); } @@ -63,6 +72,7 @@ ServiceThread::Impl::Impl(KernelCore& kernel, std::size_t num_threads, const std task(); } }); + } } void ServiceThread::Impl::QueueSyncRequest(KSession& session, @@ -88,12 +98,9 @@ void ServiceThread::Impl::QueueSyncRequest(KSession& session, } ServiceThread::Impl::~Impl() { - { - std::unique_lock lock{queue_mutex}; - stop = true; - } condition.notify_all(); - for (std::thread& thread : threads) { + for (auto& thread : threads) { + thread.request_stop(); thread.join(); } } |