summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/kernel')
-rw-r--r--src/core/hle/kernel/k_client_port.cpp (renamed from src/core/hle/kernel/client_port.cpp)31
-rw-r--r--src/core/hle/kernel/k_client_port.h (renamed from src/core/hle/kernel/client_port.h)45
-rw-r--r--src/core/hle/kernel/k_server_session.cpp2
-rw-r--r--src/core/hle/kernel/k_session.h4
-rw-r--r--src/core/hle/kernel/kernel.cpp10
-rw-r--r--src/core/hle/kernel/kernel.h6
-rw-r--r--src/core/hle/kernel/server_port.cpp15
-rw-r--r--src/core/hle/kernel/server_port.h4
-rw-r--r--src/core/hle/kernel/svc.cpp2
9 files changed, 72 insertions, 47 deletions
diff --git a/src/core/hle/kernel/client_port.cpp b/src/core/hle/kernel/k_client_port.cpp
index ce88da1c3..15bf0d4fc 100644
--- a/src/core/hle/kernel/client_port.cpp
+++ b/src/core/hle/kernel/k_client_port.cpp
@@ -2,8 +2,8 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
-#include "core/hle/kernel/client_port.h"
#include "core/hle/kernel/hle_ipc.h"
+#include "core/hle/kernel/k_client_port.h"
#include "core/hle/kernel/k_session.h"
#include "core/hle/kernel/object.h"
#include "core/hle/kernel/server_port.h"
@@ -11,18 +11,23 @@
namespace Kernel {
-ClientPort::ClientPort(KernelCore& kernel) : Object{kernel} {}
-ClientPort::~ClientPort() = default;
+KClientPort::KClientPort(KernelCore& kernel) : KSynchronizationObject{kernel} {}
+KClientPort::~KClientPort() = default;
-std::shared_ptr<ServerPort> ClientPort::GetServerPort() const {
+void KClientPort::Initialize(s32 max_sessions_, std::string&& name_) {
+ max_sessions = max_sessions_;
+ name = std::move(name_);
+}
+
+std::shared_ptr<ServerPort> KClientPort::GetServerPort() const {
return server_port;
}
-ResultVal<KClientSession*> ClientPort::Connect() {
- if (active_sessions >= max_sessions) {
+ResultVal<KClientSession*> KClientPort::Connect() {
+ if (num_sessions >= max_sessions) {
return ResultOutOfSessions;
}
- active_sessions++;
+ num_sessions++;
auto* session = Kernel::KSession::Create(kernel);
session->Initialize(name + ":ClientPort");
@@ -36,12 +41,18 @@ ResultVal<KClientSession*> ClientPort::Connect() {
return MakeResult(std::addressof(session->GetClientSession()));
}
-void ClientPort::ConnectionClosed() {
- if (active_sessions == 0) {
+void KClientPort::ConnectionClosed() {
+ if (num_sessions == 0) {
return;
}
- --active_sessions;
+ --num_sessions;
+}
+
+void KClientPort::Destroy() {}
+
+bool KClientPort::IsSignaled() const {
+ return num_sessions < max_sessions;
}
} // namespace Kernel
diff --git a/src/core/hle/kernel/client_port.h b/src/core/hle/kernel/k_client_port.h
index 0b20fef40..04ee2d664 100644
--- a/src/core/hle/kernel/client_port.h
+++ b/src/core/hle/kernel/k_client_port.h
@@ -8,7 +8,7 @@
#include <string>
#include "common/common_types.h"
-#include "core/hle/kernel/object.h"
+#include "core/hle/kernel/k_synchronization_object.h"
#include "core/hle/result.h"
namespace Kernel {
@@ -17,23 +17,16 @@ class KClientSession;
class KernelCore;
class ServerPort;
-class ClientPort final : public Object {
+class KClientPort final : public KSynchronizationObject {
+ KERNEL_AUTOOBJECT_TRAITS(KClientPort, KSynchronizationObject);
+
public:
- explicit ClientPort(KernelCore& kernel);
- ~ClientPort() override;
+ explicit KClientPort(KernelCore& kernel);
+ virtual ~KClientPort() override;
friend class ServerPort;
- std::string GetTypeName() const override {
- return "ClientPort";
- }
- std::string GetName() const override {
- return name;
- }
- static constexpr HandleType HANDLE_TYPE = HandleType::ClientPort;
- HandleType GetHandleType() const override {
- return HANDLE_TYPE;
- }
+ void Initialize(s32 max_sessions_, std::string&& name_);
std::shared_ptr<ServerPort> GetServerPort() const;
@@ -51,13 +44,29 @@ public:
*/
void ConnectionClosed();
- void Finalize() override {}
+ // Overridden virtual functions.
+ virtual void Destroy() override;
+ virtual bool IsSignaled() const override;
+
+ // DEPRECATED
+
+ std::string GetTypeName() const override {
+ return "ClientPort";
+ }
+ std::string GetName() const override {
+ return name;
+ }
+
+ static constexpr HandleType HANDLE_TYPE = HandleType::ClientPort;
+ HandleType GetHandleType() const override {
+ return HANDLE_TYPE;
+ }
private:
std::shared_ptr<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)
+ s32 max_sessions = 0; ///< Maximum number of simultaneous sessions the port can have
+ std::atomic<s32> num_sessions = 0; ///< Number of currently open sessions to this port
+ std::string name; ///< Name of client port (optional)
};
} // namespace Kernel
diff --git a/src/core/hle/kernel/k_server_session.cpp b/src/core/hle/kernel/k_server_session.cpp
index 8cd2c283c..46ba7081b 100644
--- a/src/core/hle/kernel/k_server_session.cpp
+++ b/src/core/hle/kernel/k_server_session.cpp
@@ -10,9 +10,9 @@
#include "common/logging/log.h"
#include "core/core_timing.h"
#include "core/hle/ipc_helpers.h"
-#include "core/hle/kernel/client_port.h"
#include "core/hle/kernel/handle_table.h"
#include "core/hle/kernel/hle_ipc.h"
+#include "core/hle/kernel/k_client_port.h"
#include "core/hle/kernel/k_scheduler.h"
#include "core/hle/kernel/k_server_session.h"
#include "core/hle/kernel/k_session.h"
diff --git a/src/core/hle/kernel/k_session.h b/src/core/hle/kernel/k_session.h
index 1d24e80cd..6a6fcb588 100644
--- a/src/core/hle/kernel/k_session.h
+++ b/src/core/hle/kernel/k_session.h
@@ -70,7 +70,7 @@ public:
return server;
}
- const ClientPort* GetParent() const {
+ const KClientPort* GetParent() const {
return port;
}
@@ -99,7 +99,7 @@ private:
KClientSession client;
std::atomic<std::underlying_type<State>::type> atomic_state{
static_cast<std::underlying_type<State>::type>(State::Invalid)};
- ClientPort* port{};
+ KClientPort* port{};
std::string name;
Process* process{};
bool initialized{};
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index ada993f46..c939bb903 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -26,9 +26,9 @@
#include "core/cpu_manager.h"
#include "core/device_memory.h"
#include "core/hardware_properties.h"
-#include "core/hle/kernel/client_port.h"
#include "core/hle/kernel/handle_table.h"
#include "core/hle/kernel/init/init_slab_setup.h"
+#include "core/hle/kernel/k_client_port.h"
#include "core/hle/kernel/k_memory_layout.h"
#include "core/hle/kernel/k_memory_manager.h"
#include "core/hle/kernel/k_resource_limit.h"
@@ -122,6 +122,9 @@ struct KernelCore::Impl {
preemption_event = nullptr;
+ for (auto& iter : named_ports) {
+ iter.second->Close();
+ }
named_ports.clear();
exclusive_monitor.reset();
@@ -843,8 +846,9 @@ void KernelCore::PrepareReschedule(std::size_t id) {
// TODO: Reimplement, this
}
-void KernelCore::AddNamedPort(std::string name, std::shared_ptr<ClientPort> port) {
- impl->named_ports.emplace(std::move(name), std::move(port));
+void KernelCore::AddNamedPort(std::string name, KClientPort* port) {
+ port->Open();
+ impl->named_ports.emplace(std::move(name), port);
}
KernelCore::NamedPortTable::iterator KernelCore::FindNamedPort(const std::string& name) {
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h
index 43e49603b..19b3530b4 100644
--- a/src/core/hle/kernel/kernel.h
+++ b/src/core/hle/kernel/kernel.h
@@ -29,7 +29,7 @@ struct EventType;
namespace Kernel {
-class ClientPort;
+class KClientPort;
class GlobalSchedulerContext;
class HandleTable;
class KAutoObjectWithListContainer;
@@ -60,7 +60,7 @@ constexpr EmuThreadHandle EmuThreadHandleReserved{1ULL << 63};
/// Represents a single instance of the kernel.
class KernelCore {
private:
- using NamedPortTable = std::unordered_map<std::string, std::shared_ptr<ClientPort>>;
+ using NamedPortTable = std::unordered_map<std::string, KClientPort*>;
public:
/// Constructs an instance of the kernel using the given System
@@ -168,7 +168,7 @@ public:
void InvalidateCpuInstructionCacheRange(VAddr addr, std::size_t size);
/// Adds a port to the named port table
- void AddNamedPort(std::string name, std::shared_ptr<ClientPort> port);
+ void AddNamedPort(std::string name, KClientPort* port);
/// Finds a port within the named port table with the given name.
NamedPortTable::iterator FindNamedPort(const std::string& name);
diff --git a/src/core/hle/kernel/server_port.cpp b/src/core/hle/kernel/server_port.cpp
index 8626b56fd..addaaa5cf 100644
--- a/src/core/hle/kernel/server_port.cpp
+++ b/src/core/hle/kernel/server_port.cpp
@@ -4,7 +4,7 @@
#include <tuple>
#include "common/assert.h"
-#include "core/hle/kernel/client_port.h"
+#include "core/hle/kernel/k_client_port.h"
#include "core/hle/kernel/k_server_session.h"
#include "core/hle/kernel/k_thread.h"
#include "core/hle/kernel/object.h"
@@ -40,15 +40,16 @@ bool ServerPort::IsSignaled() const {
ServerPort::PortPair ServerPort::CreatePortPair(KernelCore& kernel, u32 max_sessions,
std::string name) {
std::shared_ptr<ServerPort> server_port = std::make_shared<ServerPort>(kernel);
- std::shared_ptr<ClientPort> client_port = std::make_shared<ClientPort>(kernel);
+ KClientPort* client_port = new KClientPort(kernel);
- server_port->name = name + "_Server";
- client_port->name = name + "_Client";
+ KAutoObject::Create(client_port);
+
+ client_port->Initialize(max_sessions, name + "_Client");
client_port->server_port = server_port;
- client_port->max_sessions = max_sessions;
- client_port->active_sessions = 0;
- return std::make_pair(std::move(server_port), std::move(client_port));
+ server_port->name = name + "_Server";
+
+ return std::make_pair(std::move(server_port), client_port);
}
} // namespace Kernel
diff --git a/src/core/hle/kernel/server_port.h b/src/core/hle/kernel/server_port.h
index eebceaa2a..f7d443df8 100644
--- a/src/core/hle/kernel/server_port.h
+++ b/src/core/hle/kernel/server_port.h
@@ -15,7 +15,7 @@
namespace Kernel {
-class ClientPort;
+class KClientPort;
class KernelCore;
class KServerSession;
class SessionRequestHandler;
@@ -26,7 +26,7 @@ public:
~ServerPort() override;
using HLEHandler = std::shared_ptr<SessionRequestHandler>;
- using PortPair = std::pair<std::shared_ptr<ServerPort>, std::shared_ptr<ClientPort>>;
+ using PortPair = std::pair<std::shared_ptr<ServerPort>, KClientPort*>;
/**
* Creates a pair of ServerPort and an associated ClientPort.
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index fa85bd631..8d8d3dd5a 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -21,9 +21,9 @@
#include "core/core_timing.h"
#include "core/core_timing_util.h"
#include "core/cpu_manager.h"
-#include "core/hle/kernel/client_port.h"
#include "core/hle/kernel/handle_table.h"
#include "core/hle/kernel/k_address_arbiter.h"
+#include "core/hle/kernel/k_client_port.h"
#include "core/hle/kernel/k_client_session.h"
#include "core/hle/kernel/k_condition_variable.h"
#include "core/hle/kernel/k_event.h"