From 7c89cc5b8641b888b9a972947c864a307fe2e4b3 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Thu, 28 Nov 2024 01:21:23 -0800 Subject: [PATCH] FEXCore: Moves ThreadWaiting to the frontend Only in one location does the frontend actually care about this, the backend doesn't care at all. --- FEXCore/Source/Interface/Core/Core.cpp | 3 --- FEXCore/include/FEXCore/Debug/InternalThreadState.h | 1 - .../LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp | 10 +++++++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/FEXCore/Source/Interface/Core/Core.cpp b/FEXCore/Source/Interface/Core/Core.cpp index 141d0fb6f9..9b783ca2aa 100644 --- a/FEXCore/Source/Interface/Core/Core.cpp +++ b/FEXCore/Source/Interface/Core/Core.cpp @@ -875,9 +875,6 @@ uintptr_t ContextImpl::CompileBlock(FEXCore::Core::CpuStateFrame* Frame, uint64_ void ContextImpl::ExecutionThread(FEXCore::Core::InternalThreadState* Thread) { Thread->ExitReason = FEXCore::Context::ExitReason::EXIT_WAITING; - // Now notify the thread that we are initialized - Thread->ThreadWaiting.NotifyAll(); - if (StartPaused || Thread->StartPaused) { // Parent thread doesn't need to wait to run Thread->StartRunning.Wait(); diff --git a/FEXCore/include/FEXCore/Debug/InternalThreadState.h b/FEXCore/include/FEXCore/Debug/InternalThreadState.h index 3dc710a9db..a6b13e9a69 100644 --- a/FEXCore/include/FEXCore/Debug/InternalThreadState.h +++ b/FEXCore/include/FEXCore/Debug/InternalThreadState.h @@ -93,7 +93,6 @@ struct InternalThreadState : public FEXCore::Allocator::FEXAllocOperators { NonMovableUniquePtr ExecutionThread; bool StartPaused {false}; InterruptableConditionVariable StartRunning; - Event ThreadWaiting; NonMovableUniquePtr OpDispatcher; diff --git a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp index 7f2313b03e..81af609c04 100644 --- a/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp +++ b/Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp @@ -47,18 +47,24 @@ namespace FEX::HLE { struct ExecutionThreadHandler { FEXCore::Context::Context* CTX; FEX::HLE::ThreadStateObject* Thread; + Event* ThreadWaiting; }; static void* ThreadHandler(void* Data) { ExecutionThreadHandler* Handler = reinterpret_cast(Data); auto CTX = Handler->CTX; auto Thread = Handler->Thread; + auto ThreadWaiting = Handler->ThreadWaiting; FEXCore::Allocator::free(Handler); Thread->ThreadInfo.PID = ::getpid(); Thread->ThreadInfo.TID = FHU::Syscalls::gettid(); FEX::HLE::_SyscallHandler->RegisterTLSState(Thread); + + // Now notify the thread that we are initialized + ThreadWaiting->NotifyOne(); + CTX->ExecutionThread(Thread->Thread); FEX::HLE::_SyscallHandler->UninstallTLSState(Thread); FEX::HLE::_SyscallHandler->TM.DestroyThread(Thread); @@ -96,13 +102,15 @@ FEX::HLE::ThreadStateObject* CreateNewThread(FEXCore::Context::Context* CTX, FEX NewThread->Thread->StartPaused = true; // Initialize a new thread for execution. + Event ThreadWaitingEvent {}; ExecutionThreadHandler* Arg = reinterpret_cast(FEXCore::Allocator::malloc(sizeof(ExecutionThreadHandler))); Arg->CTX = CTX; Arg->Thread = NewThread; + Arg->ThreadWaiting = &ThreadWaitingEvent; NewThread->Thread->ExecutionThread = FEXCore::Threads::Thread::Create(ThreadHandler, Arg); // Wait for the thread to have started. - NewThread->Thread->ThreadWaiting.Wait(); + ThreadWaitingEvent.Wait(); if (FEX::HLE::_SyscallHandler->NeedXIDCheck()) { // The first time an application creates a thread, GLIBC installs their SETXID signal handler.