diff options
| author | 2022-11-02 20:21:32 -0400 | |
|---|---|---|
| committer | 2022-11-04 09:18:57 -0400 | |
| commit | e6fe40428c3260d551ac5c795651e2efcfdfc0ea (patch) | |
| tree | 641e807df70e320a0b003ea3e880fe3ecccb08b6 /src/core/hle/kernel/kernel.cpp | |
| parent | kernel: avoid racy behavior in global suspension (diff) | |
| download | yuzu-e6fe40428c3260d551ac5c795651e2efcfdfc0ea.tar.gz yuzu-e6fe40428c3260d551ac5c795651e2efcfdfc0ea.tar.xz yuzu-e6fe40428c3260d551ac5c795651e2efcfdfc0ea.zip | |
service_thread: register service threads to the logical owner process
Diffstat (limited to 'src/core/hle/kernel/kernel.cpp')
| -rw-r--r-- | src/core/hle/kernel/kernel.cpp | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 6df77b423..d1892e078 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp | |||
| @@ -84,7 +84,7 @@ struct KernelCore::Impl { | |||
| 84 | InitializeResourceManagers(pt_heap_region.GetAddress(), pt_heap_region.GetSize()); | 84 | InitializeResourceManagers(pt_heap_region.GetAddress(), pt_heap_region.GetSize()); |
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | RegisterHostThread(); | 87 | RegisterHostThread(nullptr); |
| 88 | 88 | ||
| 89 | default_service_thread = CreateServiceThread(kernel, "DefaultServiceThread"); | 89 | default_service_thread = CreateServiceThread(kernel, "DefaultServiceThread"); |
| 90 | } | 90 | } |
| @@ -300,15 +300,18 @@ struct KernelCore::Impl { | |||
| 300 | } | 300 | } |
| 301 | 301 | ||
| 302 | // Gets the dummy KThread for the caller, allocating a new one if this is the first time | 302 | // Gets the dummy KThread for the caller, allocating a new one if this is the first time |
| 303 | KThread* GetHostDummyThread() { | 303 | KThread* GetHostDummyThread(KThread* existing_thread) { |
| 304 | auto initialize = [this](KThread* thread) { | 304 | auto initialize = [this](KThread* thread) { |
| 305 | ASSERT(KThread::InitializeDummyThread(thread).IsSuccess()); | 305 | ASSERT(KThread::InitializeDummyThread(thread, nullptr).IsSuccess()); |
| 306 | thread->SetName(fmt::format("DummyThread:{}", GetHostThreadId())); | 306 | thread->SetName(fmt::format("DummyThread:{}", GetHostThreadId())); |
| 307 | return thread; | 307 | return thread; |
| 308 | }; | 308 | }; |
| 309 | 309 | ||
| 310 | thread_local auto raw_thread = KThread(system.Kernel()); | 310 | thread_local KThread raw_thread{system.Kernel()}; |
| 311 | thread_local auto thread = initialize(&raw_thread); | 311 | thread_local KThread* thread = nullptr; |
| 312 | if (thread == nullptr) { | ||
| 313 | thread = (existing_thread == nullptr) ? initialize(&raw_thread) : existing_thread; | ||
| 314 | } | ||
| 312 | 315 | ||
| 313 | return thread; | 316 | return thread; |
| 314 | } | 317 | } |
| @@ -323,9 +326,9 @@ struct KernelCore::Impl { | |||
| 323 | } | 326 | } |
| 324 | 327 | ||
| 325 | /// Registers a new host thread by allocating a host thread ID for it | 328 | /// Registers a new host thread by allocating a host thread ID for it |
| 326 | void RegisterHostThread() { | 329 | void RegisterHostThread(KThread* existing_thread) { |
| 327 | [[maybe_unused]] const auto this_id = GetHostThreadId(); | 330 | [[maybe_unused]] const auto this_id = GetHostThreadId(); |
| 328 | [[maybe_unused]] const auto dummy_thread = GetHostDummyThread(); | 331 | [[maybe_unused]] const auto dummy_thread = GetHostDummyThread(existing_thread); |
| 329 | } | 332 | } |
| 330 | 333 | ||
| 331 | [[nodiscard]] u32 GetCurrentHostThreadID() { | 334 | [[nodiscard]] u32 GetCurrentHostThreadID() { |
| @@ -356,7 +359,7 @@ struct KernelCore::Impl { | |||
| 356 | KThread* GetCurrentEmuThread() { | 359 | KThread* GetCurrentEmuThread() { |
| 357 | const auto thread_id = GetCurrentHostThreadID(); | 360 | const auto thread_id = GetCurrentHostThreadID(); |
| 358 | if (thread_id >= Core::Hardware::NUM_CPU_CORES) { | 361 | if (thread_id >= Core::Hardware::NUM_CPU_CORES) { |
| 359 | return GetHostDummyThread(); | 362 | return GetHostDummyThread(nullptr); |
| 360 | } | 363 | } |
| 361 | 364 | ||
| 362 | return current_thread; | 365 | return current_thread; |
| @@ -1033,8 +1036,12 @@ void KernelCore::RegisterCoreThread(std::size_t core_id) { | |||
| 1033 | impl->RegisterCoreThread(core_id); | 1036 | impl->RegisterCoreThread(core_id); |
| 1034 | } | 1037 | } |
| 1035 | 1038 | ||
| 1036 | void KernelCore::RegisterHostThread() { | 1039 | void KernelCore::RegisterHostThread(KThread* existing_thread) { |
| 1037 | impl->RegisterHostThread(); | 1040 | impl->RegisterHostThread(existing_thread); |
| 1041 | |||
| 1042 | if (existing_thread != nullptr) { | ||
| 1043 | ASSERT(GetCurrentEmuThread() == existing_thread); | ||
| 1044 | } | ||
| 1038 | } | 1045 | } |
| 1039 | 1046 | ||
| 1040 | u32 KernelCore::GetCurrentHostThreadID() const { | 1047 | u32 KernelCore::GetCurrentHostThreadID() const { |