Skip to content

Commit

Permalink
Merge pull request #4221 from Sonicadvance1/threadmanager_footexplosions
Browse files Browse the repository at this point in the history
ThreadManager: Add some sanity asserts
  • Loading branch information
Sonicadvance1 authored Dec 18, 2024
2 parents 57178ab + e58f67b commit d8ef702
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ void ThreadManager::HandleThreadDeletion(FEX::HLE::ThreadStateObject* Thread, bo
}

if (NeedsTLSUninstall) {
#if defined(ASSERTIONS_ENABLED) && ASSERTIONS_ENABLED
// Sanity check. This can only be called from the owning thread.
{
const auto pid = ::getpid();
const auto tid = FHU::Syscalls::gettid();
LOGMAN_THROW_A_FMT(Thread->ThreadInfo.PID == pid && Thread->ThreadInfo.TID == tid, "Can't delete TLS data from a different thread!");
}
#endif
FEXCore::Allocator::UninstallTLSData(Thread->Thread);
}

Expand All @@ -76,6 +84,18 @@ void ThreadManager::NotifyPause() {
}

void ThreadManager::Pause() {
#if defined(ASSERTIONS_ENABLED) && ASSERTIONS_ENABLED
// Sanity check. This can't be called from an emulation thread.
{
const auto pid = ::getpid();
const auto tid = FHU::Syscalls::gettid();
std::lock_guard lk(ThreadCreationMutex);
for (auto& Thread : Threads) {
LOGMAN_THROW_A_FMT(!(Thread->ThreadInfo.PID == pid && Thread->ThreadInfo.TID == tid), "Can't put threads to sleep from inside "
"emulation thread!");
}
}
#endif
NotifyPause();
WaitForIdle();
}
Expand Down Expand Up @@ -164,6 +184,15 @@ void ThreadManager::Stop(bool IgnoreCurrentThread) {

void ThreadManager::SleepThread(FEXCore::Context::Context* CTX, FEXCore::Core::CpuStateFrame* Frame) {
auto ThreadObject = FEX::HLE::ThreadManager::GetStateObjectFromCPUState(Frame);
#if defined(ASSERTIONS_ENABLED) && ASSERTIONS_ENABLED
// Sanity check. This can only be called from the owning thread.
{
const auto pid = ::getpid();
const auto tid = FHU::Syscalls::gettid();
LOGMAN_THROW_A_FMT(ThreadObject->ThreadInfo.PID == pid && ThreadObject->ThreadInfo.TID == tid, "Can't delete TLS data from a different "
"thread!");
}
#endif

--IdleWaitRefCount;
IdleWaitCV.notify_all();
Expand Down

0 comments on commit d8ef702

Please sign in to comment.