From 8d6342384b3932e18e98c223debd192ae1b73216 Mon Sep 17 00:00:00 2001 From: Weiyi Wang Date: Tue, 2 Apr 2019 12:30:03 -0400 Subject: HLE/IPC: HLEContext can memorize the client thread and use it for SleepClientThread This reduces the boilerplate that services have to write out the current thread explicitly. Using current thread instead of client thread is also semantically incorrect, and will be a problem when we implement multicore (at which time there will be multiple current threads) --- src/core/hle/kernel/hle_ipc.cpp | 7 ++++--- src/core/hle/kernel/hle_ipc.h | 8 ++++---- src/core/hle/kernel/server_session.cpp | 2 +- src/core/hle/service/vi/vi.cpp | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index fe710eb6e..182f6f792 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp @@ -43,7 +43,7 @@ void SessionRequestHandler::ClientDisconnected(const SharedPtr& s } SharedPtr HLERequestContext::SleepClientThread( - SharedPtr thread, const std::string& reason, u64 timeout, WakeupCallback&& callback, + const std::string& reason, u64 timeout, WakeupCallback&& callback, SharedPtr writable_event) { // Put the client thread to sleep until the wait event is signaled or the timeout expires. thread->SetWakeupCallback([context = *this, callback]( @@ -76,8 +76,9 @@ SharedPtr HLERequestContext::SleepClientThread( return writable_event; } -HLERequestContext::HLERequestContext(SharedPtr server_session) - : server_session(std::move(server_session)) { +HLERequestContext::HLERequestContext(SharedPtr server_session, + SharedPtr thread) + : server_session(std::move(server_session)), thread(thread) { cmd_buf[0] = 0; } diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h index 2bdd9f02c..ccf5e56aa 100644 --- a/src/core/hle/kernel/hle_ipc.h +++ b/src/core/hle/kernel/hle_ipc.h @@ -97,7 +97,7 @@ protected: */ class HLERequestContext { public: - explicit HLERequestContext(SharedPtr session); + explicit HLERequestContext(SharedPtr session, SharedPtr thread); ~HLERequestContext(); /// Returns a pointer to the IPC command buffer for this request. @@ -119,7 +119,6 @@ public: /** * Puts the specified guest thread to sleep until the returned event is signaled or until the * specified timeout expires. - * @param thread Thread to be put to sleep. * @param reason Reason for pausing the thread, to be used for debugging purposes. * @param timeout Timeout in nanoseconds after which the thread will be awoken and the callback * invoked with a Timeout reason. @@ -130,8 +129,8 @@ public: * created. * @returns Event that when signaled will resume the thread and call the callback function. */ - SharedPtr SleepClientThread(SharedPtr thread, const std::string& reason, - u64 timeout, WakeupCallback&& callback, + SharedPtr SleepClientThread(const std::string& reason, u64 timeout, + WakeupCallback&& callback, SharedPtr writable_event = nullptr); /// Populates this context with data from the requesting process/thread. @@ -268,6 +267,7 @@ private: std::array cmd_buf; SharedPtr server_session; + SharedPtr thread; // TODO(yuriks): Check common usage of this and optimize size accordingly boost::container::small_vector, 8> move_objects; boost::container::small_vector, 8> copy_objects; diff --git a/src/core/hle/kernel/server_session.cpp b/src/core/hle/kernel/server_session.cpp index 696a82cd9..30b2bfb5a 100644 --- a/src/core/hle/kernel/server_session.cpp +++ b/src/core/hle/kernel/server_session.cpp @@ -130,7 +130,7 @@ ResultCode ServerSession::HandleSyncRequest(SharedPtr thread) { // The ServerSession received a sync request, this means that there's new data available // from its ClientSession, so wake up any threads that may be waiting on a svcReplyAndReceive or // similar. - Kernel::HLERequestContext context(this); + Kernel::HLERequestContext context(this, thread); u32* cmd_buf = (u32*)Memory::GetPointer(thread->GetTLSAddress()); context.PopulateFromIncomingCommandBuffer(kernel.CurrentProcess()->GetHandleTable(), cmd_buf); diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp index 4e17249a9..f1fa6ccd1 100644 --- a/src/core/hle/service/vi/vi.cpp +++ b/src/core/hle/service/vi/vi.cpp @@ -556,7 +556,7 @@ private: } else { // Wait the current thread until a buffer becomes available ctx.SleepClientThread( - Kernel::GetCurrentThread(), "IHOSBinderDriver::DequeueBuffer", -1, + "IHOSBinderDriver::DequeueBuffer", -1, [=](Kernel::SharedPtr thread, Kernel::HLERequestContext& ctx, Kernel::ThreadWakeupReason reason) { // Repeat TransactParcel DequeueBuffer when a buffer is available -- cgit v1.2.3 From 5993133d5e3830f5b5ee166086bfe6d019a9b8c8 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sun, 19 May 2019 02:14:30 +0200 Subject: Address review comment Co-Authored-By: Mat M. --- src/core/hle/kernel/hle_ipc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index 182f6f792..dd4eb0978 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp @@ -78,7 +78,7 @@ SharedPtr HLERequestContext::SleepClientThread( HLERequestContext::HLERequestContext(SharedPtr server_session, SharedPtr thread) - : server_session(std::move(server_session)), thread(thread) { + : server_session(std::move(server_session)), thread(std::move(thread)) { cmd_buf[0] = 0; } -- cgit v1.2.3