From 802eaee9c8492ca83f42c15ec1c88ec7eb18067d Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Thu, 28 Nov 2024 23:03:27 -0800 Subject: [PATCH] FEXCore: Moves InternalThreadState ExecutionThread to the frontend Once again this is another frontend construct, so move it to ThreadStateObject --- FEXCore/include/FEXCore/Debug/InternalThreadState.h | 1 - Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp | 2 +- .../LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp | 2 +- .../LinuxEmulation/LinuxSyscalls/ThreadManager.cpp | 10 +++++----- .../Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h | 2 ++ 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/FEXCore/include/FEXCore/Debug/InternalThreadState.h b/FEXCore/include/FEXCore/Debug/InternalThreadState.h index 44446f964b..8005a5a460 100644 --- a/FEXCore/include/FEXCore/Debug/InternalThreadState.h +++ b/FEXCore/include/FEXCore/Debug/InternalThreadState.h @@ -88,7 +88,6 @@ struct InternalThreadState : public FEXCore::Allocator::FEXAllocOperators { FEXCore::Context::Context* const CTX; - NonMovableUniquePtr ExecutionThread; NonMovableUniquePtr OpDispatcher; diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp index 281ca869b0..d2c578669b 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.cpp @@ -661,7 +661,7 @@ uint64_t CloneHandler(FEXCore::Core::CpuStateFrame* Frame, FEX::HLE::clone3_args if (flags & CLONE_VFORK) { // If VFORK is set then the calling process is suspended until the thread exits with execve or exit - NewThread->Thread->ExecutionThread->join(nullptr); + NewThread->ExecutionThread->join(nullptr); // Normally a thread cleans itself up on exit. But because we need to join, we are now responsible FEX::HLE::_SyscallHandler->TM.DestroyThread(NewThread); diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp index c8886abf53..d074c241d5 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp @@ -111,7 +111,7 @@ FEX::HLE::ThreadStateObject* CreateNewThread(FEXCore::Context::Context* CTX, FEX .CTX = CTX, .Thread = NewThread, }; - NewThread->Thread->ExecutionThread = FEXCore::Threads::Thread::Create(ThreadHandler, &Arg); + NewThread->ExecutionThread = FEXCore::Threads::Thread::Create(ThreadHandler, &Arg); // Wait for the thread to have started. Arg.ThreadWaiting.Wait(); diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.cpp index c92d7138d7..cbbe999fd4 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.cpp @@ -47,13 +47,13 @@ void ThreadManager::StopThread(FEX::HLE::ThreadStateObject* Thread) { } void ThreadManager::HandleThreadDeletion(FEX::HLE::ThreadStateObject* Thread, bool NeedsTLSUninstall) { - if (Thread->Thread->ExecutionThread) { - if (Thread->Thread->ExecutionThread->joinable()) { - Thread->Thread->ExecutionThread->join(nullptr); + if (Thread->ExecutionThread) { + if (Thread->ExecutionThread->joinable()) { + Thread->ExecutionThread->join(nullptr); } - if (Thread->Thread->ExecutionThread->IsSelf()) { - Thread->Thread->ExecutionThread->detach(); + if (Thread->ExecutionThread->IsSelf()) { + Thread->ExecutionThread->detach(); } } diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h index 5fcbfa632a..16a58f8e87 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h @@ -75,6 +75,8 @@ struct ThreadStateObject : public FEXCore::Allocator::FEXAllocOperators { // personality emulation. uint32_t persona {}; + FEXCore::Core::NonMovableUniquePtr ExecutionThread; + // Thread signaling information std::atomic SignalReason {SignalEvent::Nothing};