[Kernel] Retain handles and not objects in XThread

This fixes cases introduced by 52e836d0f81e752ba368717e68773b591adfa9cf
where thread handles get closed before the thread finishes.
Handle was assumed to be alive there, which was not true as
threads self-referenced only their objects, not their handles.

Affected games: Payday 2 Demo
This commit is contained in:
Silent 2019-11-30 19:22:39 +01:00 committed by Gliniak
parent ef029f7f4b
commit 5cffd8d624
1 changed files with 7 additions and 7 deletions

View File

@ -366,7 +366,7 @@ X_STATUS XThread::Create() {
InitializeGuestObject(); InitializeGuestObject();
// Always retain when starting - the thread owns itself until exited. // Always retain when starting - the thread owns itself until exited.
Retain(); RetainHandle();
xe::threading::Thread::CreationParameters params; xe::threading::Thread::CreationParameters params;
params.stack_size = 16 * 1024 * 1024; // Allocate a big host stack. params.stack_size = 16 * 1024 * 1024; // Allocate a big host stack.
@ -407,7 +407,7 @@ X_STATUS XThread::Create() {
xe::Profiler::ThreadExit(); xe::Profiler::ThreadExit();
// Release the self-reference to the thread. // Release the self-reference to the thread.
Release(); ReleaseHandle();
}); });
if (!thread_) { if (!thread_) {
@ -466,7 +466,7 @@ X_STATUS XThread::Exit(int exit_code) {
xe::Profiler::ThreadExit(); xe::Profiler::ThreadExit();
running_ = false; running_ = false;
Release(); ReleaseHandle();
// NOTE: this does not return! // NOTE: this does not return!
xe::threading::Thread::Exit(exit_code); xe::threading::Thread::Exit(exit_code);
@ -486,11 +486,11 @@ X_STATUS XThread::Terminate(int exit_code) {
running_ = false; running_ = false;
if (XThread::IsInThread(this)) { if (XThread::IsInThread(this)) {
Release(); ReleaseHandle();
xe::threading::Thread::Exit(exit_code); xe::threading::Thread::Exit(exit_code);
} else { } else {
thread_->Terminate(exit_code); thread_->Terminate(exit_code);
Release(); ReleaseHandle();
} }
return X_STATUS_SUCCESS; return X_STATUS_SUCCESS;
@ -985,7 +985,7 @@ object_ref<XThread> XThread::Restore(KernelState* kernel_state,
context->vscr_sat = state.context.vscr_sat; context->vscr_sat = state.context.vscr_sat;
// Always retain when starting - the thread owns itself until exited. // Always retain when starting - the thread owns itself until exited.
thread->Retain(); thread->RetainHandle();
xe::threading::Thread::CreationParameters params; xe::threading::Thread::CreationParameters params;
params.create_suspended = true; // Not done restoring yet. params.create_suspended = true; // Not done restoring yet.
@ -1023,7 +1023,7 @@ object_ref<XThread> XThread::Restore(KernelState* kernel_state,
xe::Profiler::ThreadExit(); xe::Profiler::ThreadExit();
// Release the self-reference to the thread. // Release the self-reference to the thread.
thread->Release(); thread->ReleaseHandle();
}); });
// Notify processor we were recreated. // Notify processor we were recreated.