Use the actual thread handle as a wait handle, add bool XThread::running

This commit is contained in:
Dr. Chat 2015-07-05 15:43:09 -05:00
parent 5ccea06e7f
commit 57e89e72b1
2 changed files with 9 additions and 15 deletions

View File

@ -52,7 +52,8 @@ XThread::XThread(KernelState* kernel_state, uint32_t stack_size,
priority_(0), priority_(0),
affinity_(0), affinity_(0),
irql_(0), irql_(0),
guest_thread_(guest_thread) { guest_thread_(guest_thread),
running_(false) {
creation_params_.stack_size = stack_size; creation_params_.stack_size = stack_size;
creation_params_.xapi_thread_startup = xapi_thread_startup; creation_params_.xapi_thread_startup = xapi_thread_startup;
creation_params_.start_address = start_address; creation_params_.start_address = start_address;
@ -69,9 +70,6 @@ XThread::XThread(KernelState* kernel_state, uint32_t stack_size,
apc_list_ = new NativeList(kernel_state->memory()); apc_list_ = new NativeList(kernel_state->memory());
event_ = object_ref<XEvent>(new XEvent(kernel_state));
event_->Initialize(true, false);
char thread_name[32]; char thread_name[32];
snprintf(thread_name, xe::countof(thread_name), "XThread%04X", handle()); snprintf(thread_name, xe::countof(thread_name), "XThread%04X", handle());
set_name(thread_name); set_name(thread_name);
@ -86,8 +84,6 @@ XThread::~XThread() {
delete apc_list_; delete apc_list_;
event_.reset();
PlatformDestroy(); PlatformDestroy();
if (thread_state_) { if (thread_state_) {
@ -342,9 +338,6 @@ X_STATUS XThread::Exit(int exit_code) {
// TODO(benvanik): set exit code in thread state block // TODO(benvanik): set exit code in thread state block
// TODO(benvanik); dispatch events? waiters? etc? // TODO(benvanik); dispatch events? waiters? etc?
if (event_) {
event_->Set(0, false);
}
RundownAPCs(); RundownAPCs();
kernel_state()->OnThreadExit(this); kernel_state()->OnThreadExit(this);
@ -353,6 +346,7 @@ X_STATUS XThread::Exit(int exit_code) {
current_thread_tls = nullptr; current_thread_tls = nullptr;
xe::Profiler::ThreadExit(); xe::Profiler::ThreadExit();
running_ = false;
Release(); Release();
X_STATUS return_code = PlatformExit(exit_code); X_STATUS return_code = PlatformExit(exit_code);
if (XFAILED(return_code)) { if (XFAILED(return_code)) {
@ -362,11 +356,9 @@ X_STATUS XThread::Exit(int exit_code) {
} }
X_STATUS XThread::Terminate(int exit_code) { X_STATUS XThread::Terminate(int exit_code) {
if (event_) {
event_->Set(0, false);
}
// TODO: Inform the profiler that this thread is exiting. // TODO: Inform the profiler that this thread is exiting.
running_ = false;
Release(); Release();
X_STATUS status = PlatformTerminate(exit_code); X_STATUS status = PlatformTerminate(exit_code);
if (XFAILED(status)) { if (XFAILED(status)) {
@ -501,6 +493,7 @@ void XThread::Execute() {
XELOGKERNEL("XThread::Execute thid %d (handle=%.8X, '%s', native=%.8X)", XELOGKERNEL("XThread::Execute thid %d (handle=%.8X, '%s', native=%.8X)",
thread_id_, handle(), name_.c_str(), thread_id_, handle(), name_.c_str(),
xe::threading::current_thread_id()); xe::threading::current_thread_id());
running_ = true;
// Let the kernel know we are starting. // Let the kernel know we are starting.
kernel_state()->OnThreadExecute(this); kernel_state()->OnThreadExecute(this);
@ -530,6 +523,7 @@ void XThread::Execute() {
// Treat the return code as an implicit exit code. // Treat the return code as an implicit exit code.
} }
running_ = false;
Exit(exit_code); Exit(exit_code);
} }
@ -786,7 +780,7 @@ X_STATUS XThread::Delay(uint32_t processor_mode, uint32_t alertable,
} }
} }
void* XThread::GetWaitHandle() { return event_->GetWaitHandle(); } void* XThread::GetWaitHandle() { return thread_handle_; }
XHostThread::XHostThread(KernelState* kernel_state, uint32_t stack_size, XHostThread::XHostThread(KernelState* kernel_state, uint32_t stack_size,
uint32_t creation_flags, std::function<int()> host_fn) uint32_t creation_flags, std::function<int()> host_fn)

View File

@ -93,6 +93,7 @@ class XThread : public XObject {
uint32_t pcr_ptr() const { return pcr_address_; } uint32_t pcr_ptr() const { return pcr_address_; }
uint32_t thread_state_ptr() const { return thread_state_address_; } uint32_t thread_state_ptr() const { return thread_state_address_; }
bool guest_thread() const { return guest_thread_; } bool guest_thread() const { return guest_thread_; }
bool running() const { return running_; }
cpu::ThreadState* thread_state() const { return thread_state_; } cpu::ThreadState* thread_state() const { return thread_state_; }
uint32_t thread_id() const { return thread_id_; } uint32_t thread_id() const { return thread_id_; }
@ -160,6 +161,7 @@ class XThread : public XObject {
uint32_t thread_state_address_; uint32_t thread_state_address_;
cpu::ThreadState* thread_state_; cpu::ThreadState* thread_state_;
bool guest_thread_; // Launched into guest code? bool guest_thread_; // Launched into guest code?
bool running_;
std::string name_; std::string name_;
@ -169,8 +171,6 @@ class XThread : public XObject {
std::atomic<uint32_t> irql_; std::atomic<uint32_t> irql_;
xe::mutex apc_lock_; xe::mutex apc_lock_;
NativeList* apc_list_; NativeList* apc_list_;
object_ref<XEvent> event_;
}; };
class XHostThread : public XThread { class XHostThread : public XThread {