Kernel: pass ref to port

This commit is contained in:
Weiyi Wang 2018-10-12 19:00:16 -04:00
parent c141657d83
commit 1213a298df
12 changed files with 37 additions and 25 deletions

View file

@ -13,7 +13,7 @@
namespace Kernel {
ClientPort::ClientPort() = default;
ClientPort::ClientPort(KernelSystem& kernel) {}
ClientPort::~ClientPort() = default;
ResultVal<SharedPtr<ClientSession>> ClientPort::Connect() {

View file

@ -48,13 +48,15 @@ public:
void ConnectionClosed();
private:
ClientPort();
explicit ClientPort(KernelSystem& kernel);
~ClientPort() override;
SharedPtr<ServerPort> server_port; ///< ServerPort associated with this client port.
u32 max_sessions = 0; ///< Maximum number of simultaneous sessions the port can have
u32 active_sessions = 0; ///< Number of currently open sessions to this port
std::string name; ///< Name of client port (optional)
friend class KernelSystem;
};
} // namespace Kernel

View file

@ -19,6 +19,8 @@ class Process;
class Thread;
class Semaphore;
class Timer;
class ClientPort;
class ServerPort;
enum class ResetType {
OneShot,
@ -93,6 +95,16 @@ public:
* @return The created Timer
*/
SharedPtr<Timer> CreateTimer(ResetType reset_type, std::string name = "Unknown");
/**
* Creates a pair of ServerPort and an associated ClientPort.
*
* @param max_sessions Maximum number of sessions to the port
* @param name Optional name of the ports
* @return The created port tuple
*/
std::tuple<SharedPtr<ServerPort>, SharedPtr<ClientPort>> CreatePortPair(
u32 max_sessions, std::string name = "UnknownPort");
};
} // namespace Kernel

View file

@ -13,7 +13,7 @@
namespace Kernel {
ServerPort::ServerPort() {}
ServerPort::ServerPort(KernelSystem& kernel) {}
ServerPort::~ServerPort() {}
ResultVal<SharedPtr<ServerSession>> ServerPort::Accept() {
@ -35,11 +35,11 @@ void ServerPort::Acquire(Thread* thread) {
ASSERT_MSG(!ShouldWait(thread), "object unavailable!");
}
std::tuple<SharedPtr<ServerPort>, SharedPtr<ClientPort>> ServerPort::CreatePortPair(
std::tuple<SharedPtr<ServerPort>, SharedPtr<ClientPort>> KernelSystem::CreatePortPair(
u32 max_sessions, std::string name) {
SharedPtr<ServerPort> server_port(new ServerPort);
SharedPtr<ClientPort> client_port(new ClientPort);
SharedPtr<ServerPort> server_port(new ServerPort(*this));
SharedPtr<ClientPort> client_port(new ClientPort(*this));
server_port->name = name + "_Server";
client_port->name = name + "_Client";

View file

@ -20,16 +20,6 @@ class SessionRequestHandler;
class ServerPort final : public WaitObject {
public:
/**
* Creates a pair of ServerPort and an associated ClientPort.
*
* @param max_sessions Maximum number of sessions to the port
* @param name Optional name of the ports
* @return The created port tuple
*/
static std::tuple<SharedPtr<ServerPort>, SharedPtr<ClientPort>> CreatePortPair(
u32 max_sessions, std::string name = "UnknownPort");
std::string GetTypeName() const override {
return "ServerPort";
}
@ -69,8 +59,10 @@ public:
void Acquire(Thread* thread) override;
private:
ServerPort();
explicit ServerPort(KernelSystem& kernel);
~ServerPort() override;
friend class KernelSystem;
};
} // namespace Kernel

View file

@ -1119,7 +1119,7 @@ static ResultCode CreatePort(Handle* server_port, Handle* client_port, VAddr nam
// TODO(Subv): Implement named ports.
ASSERT_MSG(name_address == 0, "Named ports are currently unimplemented");
auto ports = ServerPort::CreatePortPair(max_sessions);
auto ports = Core::System::GetInstance().Kernel().CreatePortPair(max_sessions);
CASCADE_RESULT(*client_port,
g_handle_table.Create(std::move(std::get<SharedPtr<ClientPort>>(ports))));
// Note: The 3DS kernel also leaks the client port handle if the server port handle fails to be