From 0238bdf65b1ce149c11a7422634327f5b16ca9ed Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Fri, 15 Oct 2021 19:59:29 -0700 Subject: [PATCH] tipc: enable named-thread dispatch --- .../impl/ams_system_thread_definitions.hpp | 5 ++-- .../stratosphere/tipc/tipc_server_manager.hpp | 28 +++++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/libstratosphere/include/stratosphere/ams/impl/ams_system_thread_definitions.hpp b/libstratosphere/include/stratosphere/ams/impl/ams_system_thread_definitions.hpp index c183b21e..f7684adb 100644 --- a/libstratosphere/include/stratosphere/ams/impl/ams_system_thread_definitions.hpp +++ b/libstratosphere/include/stratosphere/ams/impl/ams_system_thread_definitions.hpp @@ -28,6 +28,7 @@ namespace ams::impl { /* sm. */ AMS_DEFINE_SYSTEM_THREAD(-1, sm, Main); + AMS_DEFINE_SYSTEM_THREAD(-1, sm, DispatcherThread); /* spl. */ AMS_DEFINE_SYSTEM_THREAD(-1, spl, Main); @@ -177,5 +178,5 @@ namespace ams::impl { } -#define AMS_GET_SYSTEM_THREAD_PRIORITY(__AMS_MODULE__, __AMS_THREAD_NAME__) ::ams::impl::SystemThreadDefinition_##__AMS_MODULE__##_##__AMS_THREAD_NAME__.priority -#define AMS_GET_SYSTEM_THREAD_NAME(__AMS_MODULE__, __AMS_THREAD_NAME__) ::ams::impl::SystemThreadDefinition_##__AMS_MODULE__##_##__AMS_THREAD_NAME__.name +#define AMS_GET_SYSTEM_THREAD_PRIORITY(__AMS_MODULE__, __AMS_THREAD_NAME__) ( ::ams::impl::SystemThreadDefinition_##__AMS_MODULE__##_##__AMS_THREAD_NAME__ ).priority +#define AMS_GET_SYSTEM_THREAD_NAME(__AMS_MODULE__, __AMS_THREAD_NAME__) ( ::ams::impl::SystemThreadDefinition_##__AMS_MODULE__##_##__AMS_THREAD_NAME__ ).name diff --git a/libstratosphere/include/stratosphere/tipc/tipc_server_manager.hpp b/libstratosphere/include/stratosphere/tipc/tipc_server_manager.hpp index 4ae593f9..dcdb6f59 100644 --- a/libstratosphere/include/stratosphere/tipc/tipc_server_manager.hpp +++ b/libstratosphere/include/stratosphere/tipc/tipc_server_manager.hpp @@ -379,10 +379,15 @@ namespace ams::tipc { } template - void InitializePortThread(s32 priority) { + void InitializePortThread(s32 priority, const char *name) { /* Create the thread. */ R_ABORT_UNLESS(os::CreateThread(m_port_threads + Ix, &LoopAutoForPortThreadFunction, this, s_port_stacks + Ix, ThreadStackSize, priority)); + /* Set the thread name pointer. */ + if (name != nullptr) { + os::SetThreadNamePointer(m_port_threads + Ix, name); + } + /* Start the thread. */ os::StartThread(m_port_threads + Ix); } @@ -420,7 +425,7 @@ namespace ams::tipc { [thread_priority, this](std::index_sequence) ALWAYS_INLINE_LAMBDA { /* Create all threads. */ - (this->InitializePortThread(thread_priority), ...); + (this->InitializePortThread(thread_priority, nullptr), ...); }(std::make_index_sequence()); } @@ -428,6 +433,25 @@ namespace ams::tipc { this->LoopAutoForPort(); } + void LoopAuto(int priority, const char *name) { + /* If we have additional threads, create and start them. */ + if constexpr (NumPorts > 1) { + [priority, name, this](std::index_sequence) ALWAYS_INLINE_LAMBDA { + /* Create all threads. */ + (this->InitializePortThread(priority, name), ...); + }(std::make_index_sequence()); + } + + /* Check current thread. */ + { + AMS_ASSERT(priority == os::GetThreadPriority(os::GetCurrentThread())); + /* N does not do: os::SetThreadNamePointer(os::GetCurrentThread(), name); */ + } + + /* Process for the last port. */ + this->LoopAutoForPort(); + } + tipc::ServiceObjectBase *AllocateObject(size_t port_index, os::NativeHandle handle, DeferralManagerBaseType &deferral_manager) { /* Check that the port index is valid. */ AMS_ABORT_UNLESS(port_index < NumPorts);