|
|
@ -11,6 +11,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include "common/assert.h"
|
|
|
|
#include "common/assert.h"
|
|
|
|
#include "common/scope_exit.h"
|
|
|
|
#include "common/scope_exit.h"
|
|
|
|
|
|
|
|
#include "common/thread.h"
|
|
|
|
#include "core/core.h"
|
|
|
|
#include "core/core.h"
|
|
|
|
#include "core/hle/kernel/kernel.h"
|
|
|
|
#include "core/hle/kernel/kernel.h"
|
|
|
|
#include "core/hle/kernel/server_session.h"
|
|
|
|
#include "core/hle/kernel/server_session.h"
|
|
|
@ -22,7 +23,7 @@ namespace Kernel {
|
|
|
|
|
|
|
|
|
|
|
|
class ServiceThread::Impl final {
|
|
|
|
class ServiceThread::Impl final {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
explicit Impl(KernelCore& kernel, std::size_t num_threads);
|
|
|
|
explicit Impl(KernelCore& kernel, std::size_t num_threads, const std::string& name);
|
|
|
|
~Impl();
|
|
|
|
~Impl();
|
|
|
|
|
|
|
|
|
|
|
|
void QueueSyncRequest(ServerSession& session, std::shared_ptr<HLERequestContext>&& context);
|
|
|
|
void QueueSyncRequest(ServerSession& session, std::shared_ptr<HLERequestContext>&& context);
|
|
|
@ -32,12 +33,16 @@ private:
|
|
|
|
std::queue<std::function<void()>> requests;
|
|
|
|
std::queue<std::function<void()>> requests;
|
|
|
|
std::mutex queue_mutex;
|
|
|
|
std::mutex queue_mutex;
|
|
|
|
std::condition_variable condition;
|
|
|
|
std::condition_variable condition;
|
|
|
|
|
|
|
|
const std::string service_name;
|
|
|
|
bool stop{};
|
|
|
|
bool stop{};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ServiceThread::Impl::Impl(KernelCore& kernel, std::size_t num_threads) {
|
|
|
|
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)
|
|
|
|
for (std::size_t i = 0; i < num_threads; ++i)
|
|
|
|
threads.emplace_back([&] {
|
|
|
|
threads.emplace_back([this, &kernel] {
|
|
|
|
|
|
|
|
Common::SetCurrentThreadName(std::string{"Hle_" + service_name}.c_str());
|
|
|
|
|
|
|
|
|
|
|
|
// Wait for first request before trying to acquire a render context
|
|
|
|
// Wait for first request before trying to acquire a render context
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::unique_lock lock{queue_mutex};
|
|
|
|
std::unique_lock lock{queue_mutex};
|
|
|
@ -52,7 +57,7 @@ ServiceThread::Impl::Impl(KernelCore& kernel, std::size_t num_threads) {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::unique_lock lock{queue_mutex};
|
|
|
|
std::unique_lock lock{queue_mutex};
|
|
|
|
condition.wait(lock, [this] { return stop || !requests.empty(); });
|
|
|
|
condition.wait(lock, [this] { return stop || !requests.empty(); });
|
|
|
|
if (stop && requests.empty()) {
|
|
|
|
if (stop || requests.empty()) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
task = std::move(requests.front());
|
|
|
|
task = std::move(requests.front());
|
|
|
@ -68,9 +73,14 @@ void ServiceThread::Impl::QueueSyncRequest(ServerSession& session,
|
|
|
|
std::shared_ptr<HLERequestContext>&& context) {
|
|
|
|
std::shared_ptr<HLERequestContext>&& context) {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::unique_lock lock{queue_mutex};
|
|
|
|
std::unique_lock lock{queue_mutex};
|
|
|
|
requests.emplace([session{SharedFrom(&session)}, context{std::move(context)}]() {
|
|
|
|
|
|
|
|
session->CompleteSyncRequest(*context);
|
|
|
|
// ServerSession owns the service thread, so we cannot caption a strong pointer here in the
|
|
|
|
return;
|
|
|
|
// event that the ServerSession is terminated.
|
|
|
|
|
|
|
|
std::weak_ptr<ServerSession> weak_ptr{SharedFrom(&session)};
|
|
|
|
|
|
|
|
requests.emplace([weak_ptr, context{std::move(context)}]() {
|
|
|
|
|
|
|
|
if (auto strong_ptr = weak_ptr.lock()) {
|
|
|
|
|
|
|
|
strong_ptr->CompleteSyncRequest(*context);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
condition.notify_one();
|
|
|
|
condition.notify_one();
|
|
|
@ -87,8 +97,8 @@ ServiceThread::Impl::~Impl() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ServiceThread::ServiceThread(KernelCore& kernel, std::size_t num_threads)
|
|
|
|
ServiceThread::ServiceThread(KernelCore& kernel, std::size_t num_threads, const std::string& name)
|
|
|
|
: impl{std::make_unique<Impl>(kernel, num_threads)} {}
|
|
|
|
: impl{std::make_unique<Impl>(kernel, num_threads, name)} {}
|
|
|
|
|
|
|
|
|
|
|
|
ServiceThread::~ServiceThread() = default;
|
|
|
|
ServiceThread::~ServiceThread() = default;
|
|
|
|
|
|
|
|
|
|
|
|