Merge pull request #4736 from FearlessTobi/port-2356

Port yuzu-emu/yuzu#2356: "kernel/{server_port, server_session}: Return pairs instead of tuples from pair creation functions"
This commit is contained in:
Tobias 2019-04-27 00:07:13 +02:00 committed by GitHub
commit 7ea82e7941
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 32 additions and 40 deletions

View file

@ -26,18 +26,17 @@ ResultVal<std::shared_ptr<ClientSession>> ClientPort::Connect() {
active_sessions++; active_sessions++;
// Create a new session pair, let the created sessions inherit the parent port's HLE handler. // Create a new session pair, let the created sessions inherit the parent port's HLE handler.
auto sessions = kernel.CreateSessionPair(server_port->GetName(), SharedFrom(this)); auto [server, client] = kernel.CreateSessionPair(server_port->GetName(), SharedFrom(this));
if (server_port->hle_handler) if (server_port->hle_handler)
server_port->hle_handler->ClientConnected( server_port->hle_handler->ClientConnected(server);
std::get<std::shared_ptr<ServerSession>>(sessions));
else else
server_port->pending_sessions.push_back(std::get<std::shared_ptr<ServerSession>>(sessions)); server_port->pending_sessions.push_back(server);
// Wake the threads waiting on the ServerPort // Wake the threads waiting on the ServerPort
server_port->WakeupAllWaitingThreads(); server_port->WakeupAllWaitingThreads();
return MakeResult(std::get<std::shared_ptr<ClientSession>>(sessions)); return MakeResult(client);
} }
void ClientPort::ConnectionClosed() { void ClientPort::ConnectionClosed() {

View file

@ -83,6 +83,9 @@ public:
std::function<void()> prepare_reschedule_callback, u32 system_mode); std::function<void()> prepare_reschedule_callback, u32 system_mode);
~KernelSystem(); ~KernelSystem();
using PortPair = std::pair<std::shared_ptr<ServerPort>, std::shared_ptr<ClientPort>>;
using SessionPair = std::pair<std::shared_ptr<ServerSession>, std::shared_ptr<ClientSession>>;
/** /**
* Creates an address arbiter. * Creates an address arbiter.
* *
@ -150,8 +153,7 @@ public:
* @param name Optional name of the ports * @param name Optional name of the ports
* @return The created port tuple * @return The created port tuple
*/ */
std::tuple<std::shared_ptr<ServerPort>, std::shared_ptr<ClientPort>> CreatePortPair( PortPair CreatePortPair(u32 max_sessions, std::string name = "UnknownPort");
u32 max_sessions, std::string name = "UnknownPort");
/** /**
* Creates a pair of ServerSession and an associated ClientSession. * Creates a pair of ServerSession and an associated ClientSession.
@ -159,8 +161,8 @@ public:
* @param client_port Optional The ClientPort that spawned this session. * @param client_port Optional The ClientPort that spawned this session.
* @return The created session tuple * @return The created session tuple
*/ */
std::tuple<std::shared_ptr<ServerSession>, std::shared_ptr<ClientSession>> CreateSessionPair( SessionPair CreateSessionPair(const std::string& name = "Unknown",
const std::string& name = "Unknown", std::shared_ptr<ClientPort> client_port = nullptr); std::shared_ptr<ClientPort> client_port = nullptr);
ResourceLimitList& ResourceLimit(); ResourceLimitList& ResourceLimit();
const ResourceLimitList& ResourceLimit() const; const ResourceLimitList& ResourceLimit() const;

View file

@ -35,9 +35,7 @@ void ServerPort::Acquire(Thread* thread) {
ASSERT_MSG(!ShouldWait(thread), "object unavailable!"); ASSERT_MSG(!ShouldWait(thread), "object unavailable!");
} }
std::tuple<std::shared_ptr<ServerPort>, std::shared_ptr<ClientPort>> KernelSystem::CreatePortPair( KernelSystem::PortPair KernelSystem::CreatePortPair(u32 max_sessions, std::string name) {
u32 max_sessions, std::string name) {
auto server_port{std::make_shared<ServerPort>(*this)}; auto server_port{std::make_shared<ServerPort>(*this)};
auto client_port{std::make_shared<ClientPort>(*this)}; auto client_port{std::make_shared<ClientPort>(*this)};
@ -47,7 +45,7 @@ std::tuple<std::shared_ptr<ServerPort>, std::shared_ptr<ClientPort>> KernelSyste
client_port->max_sessions = max_sessions; client_port->max_sessions = max_sessions;
client_port->active_sessions = 0; client_port->active_sessions = 0;
return std::make_tuple(std::move(server_port), std::move(client_port)); return std::make_pair(std::move(server_port), std::move(client_port));
} }
} // namespace Kernel } // namespace Kernel

View file

@ -120,8 +120,8 @@ ResultCode ServerSession::HandleSyncRequest(std::shared_ptr<Thread> thread) {
return RESULT_SUCCESS; return RESULT_SUCCESS;
} }
std::tuple<std::shared_ptr<ServerSession>, std::shared_ptr<ClientSession>> KernelSystem::SessionPair KernelSystem::CreateSessionPair(const std::string& name,
KernelSystem::CreateSessionPair(const std::string& name, std::shared_ptr<ClientPort> port) { std::shared_ptr<ClientPort> port) {
auto server_session = ServerSession::Create(*this, name + "_Server").Unwrap(); auto server_session = ServerSession::Create(*this, name + "_Server").Unwrap();
auto client_session{std::make_shared<ClientSession>(*this)}; auto client_session{std::make_shared<ClientSession>(*this)};
client_session->name = name + "_Client"; client_session->name = name + "_Client";
@ -134,7 +134,7 @@ KernelSystem::CreateSessionPair(const std::string& name, std::shared_ptr<ClientP
client_session->parent = parent; client_session->parent = parent;
server_session->parent = parent; server_session->parent = parent;
return std::make_tuple(std::move(server_session), std::move(client_session)); return std::make_pair(std::move(server_session), std::move(client_session));
} }
} // namespace Kernel } // namespace Kernel

View file

@ -1292,13 +1292,11 @@ ResultCode SVC::CreatePort(Handle* server_port, Handle* client_port, VAddr name_
std::shared_ptr<Process> current_process = kernel.GetCurrentProcess(); std::shared_ptr<Process> current_process = kernel.GetCurrentProcess();
auto ports = kernel.CreatePortPair(max_sessions); auto [server, client] = kernel.CreatePortPair(max_sessions);
CASCADE_RESULT(*client_port, current_process->handle_table.Create( CASCADE_RESULT(*client_port, current_process->handle_table.Create(std::move(client)));
std::move(std::get<std::shared_ptr<ClientPort>>(ports))));
// Note: The 3DS kernel also leaks the client port handle if the server port handle fails to be // Note: The 3DS kernel also leaks the client port handle if the server port handle fails to be
// created. // created.
CASCADE_RESULT(*server_port, current_process->handle_table.Create( CASCADE_RESULT(*server_port, current_process->handle_table.Create(std::move(server)));
std::move(std::get<std::shared_ptr<ServerPort>>(ports))));
LOG_TRACE(Kernel_SVC, "called max_sessions={}", max_sessions); LOG_TRACE(Kernel_SVC, "called max_sessions={}", max_sessions);
return RESULT_SUCCESS; return RESULT_SUCCESS;
@ -1317,14 +1315,12 @@ ResultCode SVC::CreateSessionToPort(Handle* out_client_session, Handle client_po
} }
ResultCode SVC::CreateSession(Handle* server_session, Handle* client_session) { ResultCode SVC::CreateSession(Handle* server_session, Handle* client_session) {
auto sessions = kernel.CreateSessionPair(); auto [server, client] = kernel.CreateSessionPair();
std::shared_ptr<Process> current_process = kernel.GetCurrentProcess(); std::shared_ptr<Process> current_process = kernel.GetCurrentProcess();
auto& server = std::get<std::shared_ptr<ServerSession>>(sessions);
CASCADE_RESULT(*server_session, current_process->handle_table.Create(std::move(server))); CASCADE_RESULT(*server_session, current_process->handle_table.Create(std::move(server)));
auto& client = std::get<std::shared_ptr<ClientSession>>(sessions);
CASCADE_RESULT(*client_session, current_process->handle_table.Create(std::move(client))); CASCADE_RESULT(*client_session, current_process->handle_table.Create(std::move(client)));
LOG_TRACE(Kernel_SVC, "called"); LOG_TRACE(Kernel_SVC, "called");

View file

@ -197,8 +197,7 @@ void File::OpenLinkFile(Kernel::HLERequestContext& ctx) {
using Kernel::ServerSession; using Kernel::ServerSession;
IPC::RequestParser rp(ctx, 0x080C, 0, 0); IPC::RequestParser rp(ctx, 0x080C, 0, 0);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2); IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
auto sessions = system.Kernel().CreateSessionPair(GetName()); auto [server, client] = system.Kernel().CreateSessionPair(GetName());
auto server = std::get<std::shared_ptr<ServerSession>>(sessions);
ClientConnected(server); ClientConnected(server);
FileSessionSlot* slot = GetSessionData(server); FileSessionSlot* slot = GetSessionData(server);
@ -210,7 +209,7 @@ void File::OpenLinkFile(Kernel::HLERequestContext& ctx) {
slot->subfile = false; slot->subfile = false;
rb.Push(RESULT_SUCCESS); rb.Push(RESULT_SUCCESS);
rb.PushMoveObjects(std::get<std::shared_ptr<ClientSession>>(sessions)); rb.PushMoveObjects(client);
} }
void File::OpenSubFile(Kernel::HLERequestContext& ctx) { void File::OpenSubFile(Kernel::HLERequestContext& ctx) {
@ -244,8 +243,7 @@ void File::OpenSubFile(Kernel::HLERequestContext& ctx) {
using Kernel::ClientSession; using Kernel::ClientSession;
using Kernel::ServerSession; using Kernel::ServerSession;
auto sessions = system.Kernel().CreateSessionPair(GetName()); auto [server, client] = system.Kernel().CreateSessionPair(GetName());
auto server = std::get<std::shared_ptr<ServerSession>>(sessions);
ClientConnected(server); ClientConnected(server);
FileSessionSlot* slot = GetSessionData(server); FileSessionSlot* slot = GetSessionData(server);
@ -255,12 +253,11 @@ void File::OpenSubFile(Kernel::HLERequestContext& ctx) {
slot->subfile = true; slot->subfile = true;
rb.Push(RESULT_SUCCESS); rb.Push(RESULT_SUCCESS);
rb.PushMoveObjects(std::get<std::shared_ptr<ClientSession>>(sessions)); rb.PushMoveObjects(client);
} }
std::shared_ptr<Kernel::ClientSession> File::Connect() { std::shared_ptr<Kernel::ClientSession> File::Connect() {
auto sessions = system.Kernel().CreateSessionPair(GetName()); auto [server, client] = system.Kernel().CreateSessionPair(GetName());
auto server = std::get<std::shared_ptr<Kernel::ServerSession>>(sessions);
ClientConnected(server); ClientConnected(server);
FileSessionSlot* slot = GetSessionData(server); FileSessionSlot* slot = GetSessionData(server);
@ -269,7 +266,7 @@ std::shared_ptr<Kernel::ClientSession> File::Connect() {
slot->size = backend->GetSize(); slot->size = backend->GetSize();
slot->subfile = false; slot->subfile = false;
return std::get<std::shared_ptr<Kernel::ClientSession>>(sessions); return client;
} }
std::size_t File::GetSessionFileOffset(std::shared_ptr<Kernel::ServerSession> session) { std::size_t File::GetSessionFileOffset(std::shared_ptr<Kernel::ServerSession> session) {

View file

@ -306,9 +306,9 @@ void FS_USER::OpenDirectory(Kernel::HLERequestContext& ctx) {
rb.Push(dir_res.Code()); rb.Push(dir_res.Code());
if (dir_res.Succeeded()) { if (dir_res.Succeeded()) {
std::shared_ptr<Directory> directory = *dir_res; std::shared_ptr<Directory> directory = *dir_res;
auto sessions = system.Kernel().CreateSessionPair(directory->GetName()); auto [server, client] = system.Kernel().CreateSessionPair(directory->GetName());
directory->ClientConnected(std::get<std::shared_ptr<ServerSession>>(sessions)); directory->ClientConnected(server);
rb.PushMoveObjects(std::get<std::shared_ptr<ClientSession>>(sessions)); rb.PushMoveObjects(client);
} else { } else {
LOG_ERROR(Service_FS, "failed to get a handle for directory type={} size={} data={}", LOG_ERROR(Service_FS, "failed to get a handle for directory type={} size={} data={}",
static_cast<u32>(dirname_type), dirname_size, dir_path.DebugStr()); static_cast<u32>(dirname_type), dirname_size, dir_path.DebugStr());

View file

@ -24,8 +24,8 @@ TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel
Core::Timing timing; Core::Timing timing;
Memory::MemorySystem memory; Memory::MemorySystem memory;
Kernel::KernelSystem kernel(memory, timing, [] {}, 0); Kernel::KernelSystem kernel(memory, timing, [] {}, 0);
auto session = std::get<std::shared_ptr<ServerSession>>(kernel.CreateSessionPair()); auto [server, client] = kernel.CreateSessionPair();
HLERequestContext context(kernel, std::move(session), nullptr); HLERequestContext context(kernel, std::move(server), nullptr);
auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0)); auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0));
@ -236,8 +236,8 @@ TEST_CASE("HLERequestContext::WriteToOutgoingCommandBuffer", "[core][kernel]") {
Core::Timing timing; Core::Timing timing;
Memory::MemorySystem memory; Memory::MemorySystem memory;
Kernel::KernelSystem kernel(memory, timing, [] {}, 0); Kernel::KernelSystem kernel(memory, timing, [] {}, 0);
auto session = std::get<std::shared_ptr<ServerSession>>(kernel.CreateSessionPair()); auto [server, client] = kernel.CreateSessionPair();
HLERequestContext context(kernel, std::move(session), nullptr); HLERequestContext context(kernel, std::move(server), nullptr);
auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0)); auto process = kernel.CreateProcess(kernel.CreateCodeSet("", 0));
auto* input = context.CommandBuffer(); auto* input = context.CommandBuffer();