diff options
Diffstat (limited to '')
-rw-r--r-- | src/core/hle/kernel/client_session.cpp | 16 | ||||
-rw-r--r-- | src/core/hle/kernel/kernel.cpp | 13 | ||||
-rw-r--r-- | src/core/hle/kernel/kernel.h | 2 | ||||
-rw-r--r-- | src/core/hle/kernel/server_session.cpp | 18 | ||||
-rw-r--r-- | src/core/hle/kernel/session.h | 4 |
5 files changed, 26 insertions, 27 deletions
diff --git a/src/core/hle/kernel/client_session.cpp b/src/core/hle/kernel/client_session.cpp index bc59d3306..5995a6556 100644 --- a/src/core/hle/kernel/client_session.cpp +++ b/src/core/hle/kernel/client_session.cpp @@ -16,20 +16,18 @@ ClientSession::ClientSession(KernelCore& kernel) : Object{kernel} {} ClientSession::~ClientSession() { // This destructor will be called automatically when the last ClientSession handle is closed by // the emulated application. - if (parent->server) { - parent->server->ClientDisconnected(); + if (auto server = parent->server.lock()) { + server->ClientDisconnected(); } - - parent->client = nullptr; } ResultCode ClientSession::SendSyncRequest(Thread* thread) { - // Keep ServerSession alive until we're done working with it. - if (parent->server == nullptr) - return ERR_SESSION_CLOSED_BY_REMOTE; - // Signal the server session that new data is available - return parent->server->HandleSyncRequest(SharedFrom(thread)); + if (auto server = parent->server.lock()) { + return server->HandleSyncRequest(SharedFrom(thread)); + } + + return ERR_SESSION_CLOSED_BY_REMOTE; } } // namespace Kernel diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 63ad07950..a9851113a 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -139,12 +139,12 @@ struct KernelCore::Impl { void InitializeThreads() { thread_wakeup_event_type = - system.CoreTiming().RegisterEvent("ThreadWakeupCallback", ThreadWakeupCallback); + Core::Timing::CreateEvent("ThreadWakeupCallback", ThreadWakeupCallback); } void InitializePreemption() { - preemption_event = system.CoreTiming().RegisterEvent( - "PreemptionCallback", [this](u64 userdata, s64 cycles_late) { + preemption_event = + Core::Timing::CreateEvent("PreemptionCallback", [this](u64 userdata, s64 cycles_late) { global_scheduler.PreemptThreads(); s64 time_interval = Core::Timing::msToCycles(std::chrono::milliseconds(10)); system.CoreTiming().ScheduleEvent(time_interval, preemption_event); @@ -166,8 +166,9 @@ struct KernelCore::Impl { std::shared_ptr<ResourceLimit> system_resource_limit; - Core::Timing::EventType* thread_wakeup_event_type = nullptr; - Core::Timing::EventType* preemption_event = nullptr; + std::shared_ptr<Core::Timing::EventType> thread_wakeup_event_type; + std::shared_ptr<Core::Timing::EventType> preemption_event; + // TODO(yuriks): This can be removed if Thread objects are explicitly pooled in the future, // allowing us to simply use a pool index or similar. Kernel::HandleTable thread_wakeup_callback_handle_table; @@ -269,7 +270,7 @@ u64 KernelCore::CreateNewUserProcessID() { return impl->next_user_process_id++; } -Core::Timing::EventType* KernelCore::ThreadWakeupCallbackEventType() const { +const std::shared_ptr<Core::Timing::EventType>& KernelCore::ThreadWakeupCallbackEventType() const { return impl->thread_wakeup_event_type; } diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index c74b9078f..babb531c6 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h @@ -113,7 +113,7 @@ private: u64 CreateNewThreadID(); /// Retrieves the event type used for thread wakeup callbacks. - Core::Timing::EventType* ThreadWakeupCallbackEventType() const; + const std::shared_ptr<Core::Timing::EventType>& ThreadWakeupCallbackEventType() const; /// Provides a reference to the thread wakeup callback handle table. Kernel::HandleTable& ThreadWakeupCallbackHandleTable(); diff --git a/src/core/hle/kernel/server_session.cpp b/src/core/hle/kernel/server_session.cpp index 2994fa0ac..c7db21eb2 100644 --- a/src/core/hle/kernel/server_session.cpp +++ b/src/core/hle/kernel/server_session.cpp @@ -31,8 +31,6 @@ ServerSession::~ServerSession() { if (parent->port) { parent->port->ConnectionClosed(); } - - parent->server = nullptr; } ResultVal<std::shared_ptr<ServerSession>> ServerSession::Create(KernelCore& kernel, @@ -46,11 +44,13 @@ ResultVal<std::shared_ptr<ServerSession>> ServerSession::Create(KernelCore& kern } bool ServerSession::ShouldWait(const Thread* thread) const { - // Closed sessions should never wait, an error will be returned from svcReplyAndReceive. - if (parent->client == nullptr) - return false; // Wait if we have no pending requests, or if we're currently handling a request. - return pending_requesting_threads.empty() || currently_handling != nullptr; + if (auto client = parent->client.lock()) { + return pending_requesting_threads.empty() || currently_handling != nullptr; + } + + // Closed sessions should never wait, an error will be returned from svcReplyAndReceive. + return {}; } void ServerSession::Acquire(Thread* thread) { @@ -192,9 +192,9 @@ ServerSession::SessionPair ServerSession::CreateSessionPair(KernelCore& kernel, std::shared_ptr<ClientSession> client_session = std::make_shared<ClientSession>(kernel); client_session->name = name + "_Client"; - std::shared_ptr<Session> parent(new Session); - parent->client = client_session.get(); - parent->server = server_session.get(); + std::shared_ptr<Session> parent = std::make_shared<Session>(); + parent->client = client_session; + parent->server = server_session; parent->port = std::move(port); client_session->parent = parent; diff --git a/src/core/hle/kernel/session.h b/src/core/hle/kernel/session.h index ea956813b..94395f9f5 100644 --- a/src/core/hle/kernel/session.h +++ b/src/core/hle/kernel/session.h @@ -20,8 +20,8 @@ class ServerSession; */ class Session final { public: - ClientSession* client = nullptr; ///< The client endpoint of the session. - ServerSession* server = nullptr; ///< The server endpoint of the session. + std::weak_ptr<ClientSession> client; ///< The client endpoint of the session. + std::weak_ptr<ServerSession> server; ///< The server endpoint of the session. std::shared_ptr<ClientPort> port; ///< The port that this session is associated with (optional). }; } // namespace Kernel |