|
@@ -84,7 +84,7 @@ struct KernelCore::Impl {
|
|
|
InitializeResourceManagers(pt_heap_region.GetAddress(), pt_heap_region.GetSize());
|
|
InitializeResourceManagers(pt_heap_region.GetAddress(), pt_heap_region.GetSize());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- RegisterHostThread();
|
|
|
|
|
|
|
+ RegisterHostThread(nullptr);
|
|
|
|
|
|
|
|
default_service_thread = CreateServiceThread(kernel, "DefaultServiceThread");
|
|
default_service_thread = CreateServiceThread(kernel, "DefaultServiceThread");
|
|
|
}
|
|
}
|
|
@@ -300,15 +300,18 @@ struct KernelCore::Impl {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Gets the dummy KThread for the caller, allocating a new one if this is the first time
|
|
// Gets the dummy KThread for the caller, allocating a new one if this is the first time
|
|
|
- KThread* GetHostDummyThread() {
|
|
|
|
|
|
|
+ KThread* GetHostDummyThread(KThread* existing_thread) {
|
|
|
auto initialize = [this](KThread* thread) {
|
|
auto initialize = [this](KThread* thread) {
|
|
|
- ASSERT(KThread::InitializeDummyThread(thread).IsSuccess());
|
|
|
|
|
|
|
+ ASSERT(KThread::InitializeDummyThread(thread, nullptr).IsSuccess());
|
|
|
thread->SetName(fmt::format("DummyThread:{}", GetHostThreadId()));
|
|
thread->SetName(fmt::format("DummyThread:{}", GetHostThreadId()));
|
|
|
return thread;
|
|
return thread;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- thread_local auto raw_thread = KThread(system.Kernel());
|
|
|
|
|
- thread_local auto thread = initialize(&raw_thread);
|
|
|
|
|
|
|
+ thread_local KThread raw_thread{system.Kernel()};
|
|
|
|
|
+ thread_local KThread* thread = nullptr;
|
|
|
|
|
+ if (thread == nullptr) {
|
|
|
|
|
+ thread = (existing_thread == nullptr) ? initialize(&raw_thread) : existing_thread;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
return thread;
|
|
return thread;
|
|
|
}
|
|
}
|
|
@@ -323,9 +326,9 @@ struct KernelCore::Impl {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// Registers a new host thread by allocating a host thread ID for it
|
|
/// Registers a new host thread by allocating a host thread ID for it
|
|
|
- void RegisterHostThread() {
|
|
|
|
|
|
|
+ void RegisterHostThread(KThread* existing_thread) {
|
|
|
[[maybe_unused]] const auto this_id = GetHostThreadId();
|
|
[[maybe_unused]] const auto this_id = GetHostThreadId();
|
|
|
- [[maybe_unused]] const auto dummy_thread = GetHostDummyThread();
|
|
|
|
|
|
|
+ [[maybe_unused]] const auto dummy_thread = GetHostDummyThread(existing_thread);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] u32 GetCurrentHostThreadID() {
|
|
[[nodiscard]] u32 GetCurrentHostThreadID() {
|
|
@@ -356,7 +359,7 @@ struct KernelCore::Impl {
|
|
|
KThread* GetCurrentEmuThread() {
|
|
KThread* GetCurrentEmuThread() {
|
|
|
const auto thread_id = GetCurrentHostThreadID();
|
|
const auto thread_id = GetCurrentHostThreadID();
|
|
|
if (thread_id >= Core::Hardware::NUM_CPU_CORES) {
|
|
if (thread_id >= Core::Hardware::NUM_CPU_CORES) {
|
|
|
- return GetHostDummyThread();
|
|
|
|
|
|
|
+ return GetHostDummyThread(nullptr);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return current_thread;
|
|
return current_thread;
|
|
@@ -1033,8 +1036,12 @@ void KernelCore::RegisterCoreThread(std::size_t core_id) {
|
|
|
impl->RegisterCoreThread(core_id);
|
|
impl->RegisterCoreThread(core_id);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void KernelCore::RegisterHostThread() {
|
|
|
|
|
- impl->RegisterHostThread();
|
|
|
|
|
|
|
+void KernelCore::RegisterHostThread(KThread* existing_thread) {
|
|
|
|
|
+ impl->RegisterHostThread(existing_thread);
|
|
|
|
|
+
|
|
|
|
|
+ if (existing_thread != nullptr) {
|
|
|
|
|
+ ASSERT(GetCurrentEmuThread() == existing_thread);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
u32 KernelCore::GetCurrentHostThreadID() const {
|
|
u32 KernelCore::GetCurrentHostThreadID() const {
|