[Linux/Threading] change self-suspend to wait to be resumed

This commit is contained in:
Herman S.
2025-12-13 20:54:08 +09:00
parent 15483b02af
commit 92b07391df

View File

@@ -251,15 +251,19 @@ dword_result_t NtSuspendThread_entry(dword_t handle,
(current_pcr->prcb_data.current_thread == thread->guest_object());
if (is_self_suspend) {
// Self-suspension: just increment the suspend count and return
// The thread continues running - this matches Windows/Xbox behavior
// Self-suspension: increment the suspend count and wait until
// another thread resumes us (decrements count to 0)
auto guest_thread = thread->guest_object<X_KTHREAD>();
suspend_count = guest_thread->suspend_count;
guest_thread->suspend_count++;
result = X_STATUS_SUCCESS;
XELOGD(
"Thread {:X} self-suspending (count: {}) - continuing execution",
thread->handle(), guest_thread->suspend_count);
XELOGD("Thread {:X} self-suspending (count: {}) - waiting for resume",
thread->handle(), guest_thread->suspend_count);
// Wait until suspend_count reaches 0 (resumed by another thread)
while (guest_thread->suspend_count > 0) {
xe::threading::Sleep(std::chrono::microseconds(100));
}
XELOGD("Thread {:X} resumed", thread->handle());
} else {
// Normal suspension of another thread
result = thread->Suspend(&suspend_count);