Files
FEX-Emu--FEX/External/FEXCore/Source/Utils/Threads.cpp
T
Ryan Houdek 75a62f856b Threads: Moves pthread logic to FEXLoader
This is not an attempt to clean up the various issues with the pthread
logic, instead just moving the pthread specific logic out of FEXCore in
to FEXLoader.

FEXCore needs to know how to create threads in an agnostic way. Which is
why we obfuscate the details with this inteface.

Initially this was implemented with the pthread handlers in FEXCore and
expected eventually for those to get moved to the frontend. This is the
time when it has been moved.

This is the first step towards compiling with llvm-mingw.

Still a long way to go.
2023-04-15 15:24:30 -07:00

53 lines
1.3 KiB
C++

#include <FEXCore/Utils/Allocator.h>
#include <FEXCore/Utils/LogManager.h>
#include <FEXCore/Utils/Threads.h>
#include <FEXCore/fextl/memory.h>
#include <FEXCore/fextl/deque.h>
#include <alloca.h>
#include <cstring>
#include <functional>
#include <mutex>
#include <pthread.h>
#include <stdint.h>
#include <sys/mman.h>
#include <sys/signal.h>
#include <sys/syscall.h>
#include <unistd.h>
namespace FEXCore::Threads {
fextl::unique_ptr<FEXCore::Threads::Thread> CreateThread_Default(
ThreadFunc Func,
void* Arg) {
ERROR_AND_DIE_FMT("Frontend didn't setup thread creation!");
}
void CleanupAfterFork_Default() {
ERROR_AND_DIE_FMT("Frontend didn't setup thread creation!");
}
static FEXCore::Threads::Pointers Ptrs = {
.CreateThread = CreateThread_Default,
.CleanupAfterFork = CleanupAfterFork_Default,
};
fextl::unique_ptr<FEXCore::Threads::Thread> FEXCore::Threads::Thread::Create(
ThreadFunc Func,
void* Arg) {
return Ptrs.CreateThread(Func, Arg);
}
void FEXCore::Threads::Thread::CleanupAfterFork() {
return Ptrs.CleanupAfterFork();
}
void FEXCore::Threads::Thread::SetInternalPointers(Pointers const &_Ptrs) {
memcpy(&Ptrs, &_Ptrs, sizeof(FEXCore::Threads::Pointers));
}
uint64_t SetSignalMask(uint64_t Mask) {
::syscall(SYS_rt_sigprocmask, SIG_SETMASK, &Mask, &Mask, 8);
return Mask;
}
}