From 42c657c40a64a7ead6192a55d61ac15c14559b33 Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Sat, 28 Nov 2015 13:12:01 -0600 Subject: [PATCH] Remove processor dependency on XThread for breakpoints --- src/xenia/base/threading.h | 2 ++ src/xenia/base/threading_win.cc | 11 ++++++++++- src/xenia/cpu/processor.cc | 5 +---- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/xenia/base/threading.h b/src/xenia/base/threading.h index 9b77a5a52..3278f9fcb 100644 --- a/src/xenia/base/threading.h +++ b/src/xenia/base/threading.h @@ -10,6 +10,7 @@ #ifndef XENIA_BASE_THREADING_H_ #define XENIA_BASE_THREADING_H_ +#include #include #include #include @@ -344,6 +345,7 @@ class Thread : public WaitHandle { // within that thread. static std::unique_ptr Create(CreationParameters params, std::function start_routine); + static std::unique_ptr GetCurrentThread(); // Ends the calling thread. // No destructors are called, and this function does not return. diff --git a/src/xenia/base/threading_win.cc b/src/xenia/base/threading_win.cc index d7833f221..f6b472cd6 100644 --- a/src/xenia/base/threading_win.cc +++ b/src/xenia/base/threading_win.cc @@ -442,7 +442,7 @@ std::unique_ptr Thread::Create(CreationParameters params, HANDLE handle = CreateThread(NULL, params.stack_size, ThreadStartRoutine, start_data, params.create_suspended ? CREATE_SUSPENDED : 0, NULL); - if (!handle) { + if (handle == INVALID_HANDLE_VALUE) { // TODO(benvanik): pass back? auto last_error = GetLastError(); XELOGE("Unable to CreateThread: %d", last_error); @@ -453,6 +453,15 @@ std::unique_ptr Thread::Create(CreationParameters params, return std::make_unique(handle); } +std::unique_ptr Thread::GetCurrentThread() { + HANDLE handle = ::GetCurrentThread(); + if (handle == INVALID_HANDLE_VALUE) { + return nullptr; + } + + return std::make_unique(handle); +} + void Thread::Exit(int exit_code) { ExitThread(exit_code); } } // namespace threading diff --git a/src/xenia/cpu/processor.cc b/src/xenia/cpu/processor.cc index c2a31affa..77999f305 100644 --- a/src/xenia/cpu/processor.cc +++ b/src/xenia/cpu/processor.cc @@ -27,7 +27,6 @@ #include "xenia/cpu/thread_state.h" #include "xenia/cpu/xex_module.h" #include "xenia/debug/debugger.h" -#include "xenia/kernel/xthread.h" // TODO(benvanik): based on compiler support #include "xenia/cpu/backend/x64/x64_backend.h" @@ -454,9 +453,7 @@ bool Processor::BreakpointHit(uint32_t address, uint64_t host_pc) { if (bp) { bp->Hit(host_pc); - // TODO: Remove dependency on XThread for suspending ourselves - kernel::XThread::GetCurrentThread()->Suspend(); - + xe::threading::Thread::GetCurrentThread()->Suspend(); return true; }