Skip to content

Commit

Permalink
FEXCore: Moves ThreadWaiting to the frontend
Browse files Browse the repository at this point in the history
Only in one location does the frontend actually care about this, the
backend doesn't care at all.
  • Loading branch information
Sonicadvance1 committed Nov 28, 2024
1 parent 0596a96 commit 7c89cc5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
3 changes: 0 additions & 3 deletions FEXCore/Source/Interface/Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion FEXCore/include/FEXCore/Debug/InternalThreadState.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ struct InternalThreadState : public FEXCore::Allocator::FEXAllocOperators {
NonMovableUniquePtr<FEXCore::Threads::Thread> ExecutionThread;
bool StartPaused {false};
InterruptableConditionVariable StartRunning;
Event ThreadWaiting;

NonMovableUniquePtr<FEXCore::IR::OpDispatchBuilder> OpDispatcher;

Expand Down
10 changes: 9 additions & 1 deletion Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExecutionThreadHandler*>(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);
Expand Down Expand Up @@ -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<ExecutionThreadHandler*>(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.
Expand Down

0 comments on commit 7c89cc5

Please sign in to comment.