XEvent Save/Restore (TODO: Write signaled state)
This commit is contained in:
parent
ce92dd5691
commit
6e0057020c
|
@ -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<bool>(manual_reset_);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
object_ref<XEvent> 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<bool>();
|
||||
|
||||
if (evt->manual_reset_) {
|
||||
evt->event_ = xe::threading::Event::CreateManualResetEvent(false);
|
||||
} else {
|
||||
evt->event_ = xe::threading::Event::CreateAutoResetEvent(false);
|
||||
}
|
||||
|
||||
evt->Retain();
|
||||
return object_ref<XEvent>(evt);
|
||||
}
|
||||
|
||||
} // namespace kernel
|
||||
} // namespace xe
|
||||
|
|
|
@ -39,7 +39,12 @@ class XEvent : public XObject {
|
|||
|
||||
xe::threading::WaitHandle* GetWaitHandle() override { return event_.get(); }
|
||||
|
||||
bool Save(ByteStream* stream) override;
|
||||
static object_ref<XEvent> Restore(KernelState* kernel_state,
|
||||
ByteStream* stream);
|
||||
|
||||
private:
|
||||
bool manual_reset_ = false;
|
||||
std::unique_ptr<xe::threading::Event> event_;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue