core: hle: kernel: Allocate dummy threads on host thread storage.
- Fixes a crash where on subsequent boots, long-lived host threads would have their dummy threads freed.
This commit is contained in:
parent
82a2463062
commit
5f3e77d93e
|
@ -283,15 +283,16 @@ 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() {
|
||||||
auto make_thread = [this]() {
|
auto initialize = [this](KThread* thread) {
|
||||||
KThread* thread = KThread::Create(system.Kernel());
|
|
||||||
ASSERT(KThread::InitializeDummyThread(thread).IsSuccess());
|
ASSERT(KThread::InitializeDummyThread(thread).IsSuccess());
|
||||||
thread->SetName(fmt::format("DummyThread:{}", GetHostThreadId()));
|
thread->SetName(fmt::format("DummyThread:{}", GetHostThreadId()));
|
||||||
return thread;
|
return thread;
|
||||||
};
|
};
|
||||||
|
|
||||||
thread_local KThread* saved_thread = make_thread();
|
thread_local auto raw_thread = KThread(system.Kernel());
|
||||||
return saved_thread;
|
thread_local auto thread = initialize(&raw_thread);
|
||||||
|
|
||||||
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Registers a CPU core thread by allocating a host thread ID for it
|
/// Registers a CPU core thread by allocating a host thread ID for it
|
||||||
|
|
|
@ -49,12 +49,9 @@ ServiceThread::Impl::Impl(KernelCore& kernel, std::size_t num_threads, const std
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Allocate a dummy guest thread for this host thread.
|
||||||
kernel.RegisterHostThread();
|
kernel.RegisterHostThread();
|
||||||
|
|
||||||
// Ensure the dummy thread allocated for this host thread is closed on exit.
|
|
||||||
auto* dummy_thread = kernel.GetCurrentEmuThread();
|
|
||||||
SCOPE_EXIT({ dummy_thread->Close(); });
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
std::function<void()> task;
|
std::function<void()> task;
|
||||||
|
|
||||||
|
|
Reference in New Issue