kernel/server_port: Return a std::pair from CreatePortPair()

Returns the same type that the function name describes.
This commit is contained in:
Lioncash 2019-04-06 01:36:50 -04:00 committed by fearlessTobi
parent 11754778bb
commit 1afc2c72d6
3 changed files with 8 additions and 11 deletions

View file

@ -83,6 +83,8 @@ public:
std::function<void()> prepare_reschedule_callback, u32 system_mode); std::function<void()> prepare_reschedule_callback, u32 system_mode);
~KernelSystem(); ~KernelSystem();
using PortPair = std::tuple<std::shared_ptr<ServerPort>, std::shared_ptr<ClientPort>>;
/** /**
* Creates an address arbiter. * Creates an address arbiter.
* *
@ -150,8 +152,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.

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

@ -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;