From 6e0057020ca86ea30866fd5d36c59a8b4c6232e2 Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Tue, 1 Dec 2015 18:52:19 -0600 Subject: [PATCH] XEvent Save/Restore (TODO: Write signaled state) --- src/xenia/kernel/xevent.cc | 36 ++++++++++++++++++++++++++++++++---- src/xenia/kernel/xevent.h | 5 +++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/xenia/kernel/xevent.cc b/src/xenia/kernel/xevent.cc index 079272b7b..ec51bdc7c 100644 --- a/src/xenia/kernel/xevent.cc +++ b/src/xenia/kernel/xevent.cc @@ -9,6 +9,7 @@ #include "xenia/kernel/xevent.h" +#include "xenia/base/byte_stream.h" #include "xenia/base/logging.h" namespace xe { @@ -33,13 +34,12 @@ void XEvent::Initialize(bool manual_reset, bool initial_state) { void XEvent::InitializeNative(void* native_ptr, X_DISPATCH_HEADER* header) { assert_false(event_); - bool manual_reset; switch (header->type) { case 0x00: // EventNotificationObject (manual reset) - manual_reset = true; + manual_reset_ = true; break; case 0x01: // EventSynchronizationObject (auto reset) - manual_reset = false; + manual_reset_ = false; break; default: assert_always(); @@ -47,7 +47,7 @@ void XEvent::InitializeNative(void* native_ptr, X_DISPATCH_HEADER* header) { } bool initial_state = header->signal_state ? true : false; - if (manual_reset) { + if (manual_reset_) { event_ = xe::threading::Event::CreateManualResetEvent(initial_state); } else { event_ = xe::threading::Event::CreateAutoResetEvent(initial_state); @@ -71,5 +71,33 @@ int32_t XEvent::Reset() { void XEvent::Clear() { event_->Reset(); } +bool XEvent::Save(ByteStream* stream) { + XELOGD("XEvent %.8X (%s)", handle(), manual_reset_ ? "manual" : "auto"); + SaveObject(stream); + + // TODO: Write if we're currently signaled. + stream->Write(manual_reset_); + + return true; +} + +object_ref XEvent::Restore(KernelState* kernel_state, + ByteStream* stream) { + auto evt = new XEvent(nullptr); + evt->kernel_state_ = kernel_state; + + evt->RestoreObject(stream); + evt->manual_reset_ = stream->Read(); + + if (evt->manual_reset_) { + evt->event_ = xe::threading::Event::CreateManualResetEvent(false); + } else { + evt->event_ = xe::threading::Event::CreateAutoResetEvent(false); + } + + evt->Retain(); + return object_ref(evt); +} + } // namespace kernel } // namespace xe diff --git a/src/xenia/kernel/xevent.h b/src/xenia/kernel/xevent.h index 011234b39..3fa447825 100644 --- a/src/xenia/kernel/xevent.h +++ b/src/xenia/kernel/xevent.h @@ -39,7 +39,12 @@ class XEvent : public XObject { xe::threading::WaitHandle* GetWaitHandle() override { return event_.get(); } + bool Save(ByteStream* stream) override; + static object_ref Restore(KernelState* kernel_state, + ByteStream* stream); + private: + bool manual_reset_ = false; std::unique_ptr event_; };