From c44742b0e395f7478918bc3fca4bfcb6ae43bc3e Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Wed, 2 Dec 2015 19:50:00 -0600 Subject: [PATCH] XEvent write signaled state --- src/xenia/kernel/xevent.cc | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/xenia/kernel/xevent.cc b/src/xenia/kernel/xevent.cc index ec51bdc7c..b0d1b7177 100644 --- a/src/xenia/kernel/xevent.cc +++ b/src/xenia/kernel/xevent.cc @@ -75,7 +75,23 @@ bool XEvent::Save(ByteStream* stream) { XELOGD("XEvent %.8X (%s)", handle(), manual_reset_ ? "manual" : "auto"); SaveObject(stream); - // TODO: Write if we're currently signaled. + bool signaled = true; + auto result = + xe::threading::Wait(event_.get(), false, std::chrono::milliseconds(0)); + if (result == xe::threading::WaitResult::kSuccess) { + signaled = true; + } else if (result == xe::threading::WaitResult::kTimeout) { + signaled = false; + } else { + assert_always(); + } + + if (signaled) { + // Reset the event in-case it's an auto-reset. + event_->Set(); + } + + stream->Write(signaled); stream->Write(manual_reset_); return true; @@ -87,6 +103,7 @@ object_ref XEvent::Restore(KernelState* kernel_state, evt->kernel_state_ = kernel_state; evt->RestoreObject(stream); + bool signaled = stream->Read(); evt->manual_reset_ = stream->Read(); if (evt->manual_reset_) { @@ -95,6 +112,10 @@ object_ref XEvent::Restore(KernelState* kernel_state, evt->event_ = xe::threading::Event::CreateAutoResetEvent(false); } + if (signaled) { + evt->event_->Set(); + } + evt->Retain(); return object_ref(evt); }