Remove xenia-cpu dependency on xenia-kernel
This commit is contained in:
@@ -43,7 +43,6 @@ const uint32_t XAPC::kDummyRundownRoutine;
|
||||
using xe::cpu::ppc::PPCOpcode;
|
||||
|
||||
uint32_t next_xthread_id_ = 0;
|
||||
thread_local XThread* current_thread_tls_ = nullptr;
|
||||
|
||||
XThread::XThread(KernelState* kernel_state)
|
||||
: XObject(kernel_state, kTypeThread), guest_thread_(true) {}
|
||||
@@ -102,13 +101,14 @@ XThread::~XThread() {
|
||||
}
|
||||
}
|
||||
|
||||
bool XThread::IsInThread() { return Thread::IsInThread(); }
|
||||
|
||||
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_;
|
||||
XThread* thread = reinterpret_cast<XThread*>(current_thread_tls_);
|
||||
if (!thread) {
|
||||
assert_always("Attempting to use kernel stuff from a non-kernel thread");
|
||||
}
|
||||
@@ -142,12 +142,12 @@ void XThread::set_last_error(uint32_t error_code) {
|
||||
}
|
||||
|
||||
void XThread::set_name(const std::string& name) {
|
||||
name_ = xe::format_string("%s (%.8X)", name.c_str(), handle());
|
||||
thread_name_ = xe::format_string("%s (%.8X)", name.c_str(), handle());
|
||||
|
||||
if (thread_) {
|
||||
// May be getting set before the thread is created.
|
||||
// One the thread is ready it will handle it.
|
||||
thread_->set_name(name_);
|
||||
thread_->set_name(thread_name_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -393,10 +393,13 @@ X_STATUS XThread::Create() {
|
||||
XELOGE("CreateThread failed");
|
||||
return X_STATUS_NO_MEMORY;
|
||||
}
|
||||
thread_->set_affinity_mask(proc_mask);
|
||||
|
||||
if (!FLAGS_ignore_thread_affinities) {
|
||||
thread_->set_affinity_mask(proc_mask);
|
||||
}
|
||||
|
||||
// Set the thread name based on host ID (for easier debugging).
|
||||
if (name_.empty()) {
|
||||
if (thread_name_.empty()) {
|
||||
char thread_name[32];
|
||||
snprintf(thread_name, xe::countof(thread_name), "XThread%.04X",
|
||||
thread_->system_id());
|
||||
@@ -472,7 +475,7 @@ X_STATUS XThread::Terminate(int exit_code) {
|
||||
|
||||
void XThread::Execute() {
|
||||
XELOGKERNEL("XThread::Execute thid %d (handle=%.8X, '%s', native=%.8X)",
|
||||
thread_id_, handle(), name_.c_str(), thread_->system_id());
|
||||
thread_id_, handle(), thread_name_.c_str(), thread_->system_id());
|
||||
|
||||
// Let the kernel know we are starting.
|
||||
kernel_state()->OnThreadExecute(this);
|
||||
@@ -852,7 +855,7 @@ bool XThread::Save(ByteStream* stream) {
|
||||
}
|
||||
|
||||
stream->Write('THRD');
|
||||
stream->Write(name_);
|
||||
stream->Write(thread_name_);
|
||||
|
||||
ThreadSavedState state;
|
||||
state.thread_id = thread_id_;
|
||||
@@ -918,7 +921,7 @@ object_ref<XThread> XThread::Restore(KernelState* kernel_state,
|
||||
|
||||
XELOGD("XThread %.8X", thread->handle());
|
||||
|
||||
thread->name_ = stream->Read<std::string>();
|
||||
thread->thread_name_ = stream->Read<std::string>();
|
||||
|
||||
ThreadSavedState state;
|
||||
stream->Read(&state, sizeof(ThreadSavedState));
|
||||
@@ -1030,7 +1033,7 @@ XHostThread::XHostThread(KernelState* kernel_state, uint32_t stack_size,
|
||||
void XHostThread::Execute() {
|
||||
XELOGKERNEL(
|
||||
"XThread::Execute thid %d (handle=%.8X, '%s', native=%.8X, <host>)",
|
||||
thread_id_, handle(), name_.c_str(), thread_->system_id());
|
||||
thread_id_, handle(), thread_name_.c_str(), thread_->system_id());
|
||||
|
||||
// Let the kernel know we are starting.
|
||||
kernel_state()->OnThreadExecute(this);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "xenia/base/mutex.h"
|
||||
#include "xenia/base/threading.h"
|
||||
#include "xenia/cpu/thread.h"
|
||||
#include "xenia/cpu/thread_state.h"
|
||||
#include "xenia/kernel/util/native_list.h"
|
||||
#include "xenia/kernel/xmutant.h"
|
||||
@@ -102,7 +103,7 @@ struct X_KTHREAD {
|
||||
};
|
||||
static_assert_size(X_KTHREAD, 0xAB0);
|
||||
|
||||
class XThread : public XObject {
|
||||
class XThread : public XObject, public cpu::Thread {
|
||||
public:
|
||||
static const Type kType = kTypeThread;
|
||||
|
||||
@@ -136,18 +137,11 @@ class XThread : public XObject {
|
||||
// True if the thread is created by the guest app.
|
||||
bool is_guest_thread() const { return guest_thread_; }
|
||||
bool main_thread() const { return main_thread_; }
|
||||
// True if the thread should be paused by the debugger.
|
||||
// All threads that can run guest code must be stopped for the debugger to
|
||||
// work properly.
|
||||
bool can_debugger_suspend() const { return can_debugger_suspend_; }
|
||||
void set_can_debugger_suspend(bool value) { can_debugger_suspend_ = value; }
|
||||
bool is_running() const { return running_; }
|
||||
|
||||
cpu::ThreadState* thread_state() const { return thread_state_; }
|
||||
uint32_t thread_id() const { return thread_id_; }
|
||||
uint32_t last_error();
|
||||
void set_last_error(uint32_t error_code);
|
||||
const std::string& name() const { return name_; }
|
||||
void set_name(const std::string& name);
|
||||
|
||||
X_STATUS Create();
|
||||
@@ -211,7 +205,6 @@ class XThread : public XObject {
|
||||
std::vector<object_ref<XMutant>> pending_mutant_acquires_;
|
||||
|
||||
uint32_t thread_id_ = 0;
|
||||
std::unique_ptr<xe::threading::Thread> thread_;
|
||||
uint32_t scratch_address_ = 0;
|
||||
uint32_t scratch_size_ = 0;
|
||||
uint32_t tls_static_address_ = 0;
|
||||
@@ -222,14 +215,10 @@ class XThread : public XObject {
|
||||
uint32_t stack_alloc_size_ = 0; // Stack alloc size
|
||||
uint32_t stack_base_ = 0; // High address
|
||||
uint32_t stack_limit_ = 0; // Low address
|
||||
cpu::ThreadState* thread_state_ = nullptr;
|
||||
bool guest_thread_ = false;
|
||||
bool main_thread_ = false; // Entry-point thread
|
||||
bool can_debugger_suspend_ = true;
|
||||
bool running_ = false;
|
||||
|
||||
std::string name_;
|
||||
|
||||
int32_t priority_ = 0;
|
||||
uint32_t affinity_ = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user