diff --git a/src/xenia/base/threading.h b/src/xenia/base/threading.h index bdf70b9c4..3903d1099 100644 --- a/src/xenia/base/threading.h +++ b/src/xenia/base/threading.h @@ -343,6 +343,9 @@ class Thread : public WaitHandle { // threads that had been waiting for the thread to terminate. static void Exit(int exit_code); + // Returns the ID of the thread + virtual uint32_t id() const = 0; + // Returns the current name of the thread, if previously specified. std::string name() const { return name_; } diff --git a/src/xenia/base/threading_win.cc b/src/xenia/base/threading_win.cc index a78454c69..64da0111a 100644 --- a/src/xenia/base/threading_win.cc +++ b/src/xenia/base/threading_win.cc @@ -358,6 +358,7 @@ class Win32Thread : public Win32Handle { } int32_t priority() override { return GetThreadPriority(handle_); } + uint32_t id() const override { return GetThreadId(handle_); } void set_priority(int32_t new_priority) override { SetThreadPriority(handle_, new_priority); diff --git a/src/xenia/kernel/objects/xthread.cc b/src/xenia/kernel/objects/xthread.cc index 2add67891..008f2947b 100644 --- a/src/xenia/kernel/objects/xthread.cc +++ b/src/xenia/kernel/objects/xthread.cc @@ -62,10 +62,6 @@ XThread::XThread(KernelState* kernel_state, uint32_t stack_size, apc_list_ = new NativeList(kernel_state->memory()); - char thread_name[32]; - snprintf(thread_name, xe::countof(thread_name), "XThread%04X", handle()); - set_name(thread_name); - // The kernel does not take a reference. We must unregister in the dtor. kernel_state_->RegisterThread(this); } @@ -92,6 +88,7 @@ XThread::~XThread() { } bool XThread::IsInThread(XThread* other) { return current_thread_tls == other; } +bool XThread::IsInThread() { return current_thread_tls != nullptr; } XThread* XThread::GetCurrentThread() { XThread* thread = current_thread_tls; @@ -322,6 +319,11 @@ X_STATUS XThread::Create() { } thread_->set_affinity_mask(proc_mask); + // Set the thread name based on host ID (for easier debugging) + char thread_name[32]; + snprintf(thread_name, xe::countof(thread_name), "XThread%04X (%04X)", handle(), thread_->id()); + set_name(thread_name); + if (creation_params_.creation_flags & 0x60) { thread_->set_priority(creation_params_.creation_flags & 0x20 ? 1 : 0); } diff --git a/src/xenia/kernel/objects/xthread.h b/src/xenia/kernel/objects/xthread.h index 18b7c9b17..153e36ee0 100644 --- a/src/xenia/kernel/objects/xthread.h +++ b/src/xenia/kernel/objects/xthread.h @@ -103,6 +103,7 @@ class XThread : public XObject { virtual ~XThread(); static bool IsInThread(XThread* other); + static bool IsInThread(); static XThread* GetCurrentThread(); static uint32_t GetCurrentThreadHandle(); static uint32_t GetCurrentThreadId();