diff --git a/src/main/java/li/cil/oc2/api/bus/device/vm/VMDeviceLifecycleEventType.java b/src/main/java/li/cil/oc2/api/bus/device/vm/VMDeviceLifecycleEventType.java index 08c9188a..2b57d6be 100644 --- a/src/main/java/li/cil/oc2/api/bus/device/vm/VMDeviceLifecycleEventType.java +++ b/src/main/java/li/cil/oc2/api/bus/device/vm/VMDeviceLifecycleEventType.java @@ -1,6 +1,29 @@ package li.cil.oc2.api.bus.device.vm; public enum VMDeviceLifecycleEventType { + /** + * Fired exactly once, when the VM first starts running. + *
+ * Fired after all devices reported success from {@link VMDevice#load(VMContext)}. + *
+ * If a running VM is restored from a saved state, this event will not be fired. It is + * intended for initializing the VM state on boot, e.g. by loading initial executable + * code into memory. + *
+ * This is invoked from the worker thread running the VM. + */ + INITIALIZING, + + /** + * Fired when the VM is paused, typically before state is persisted. + *
+ * Allows devices that offer interaction to external code-flow to suspend + * such interactions until {@link #RESUMED_RUNNING} is fired. This is required + * if such interactions may modify VM state, to prevent corrupting data being + * serialized asynchronously. + */ + PAUSING, + /** * Fired when the VM resumes running. *
@@ -13,17 +36,16 @@ public enum VMDeviceLifecycleEventType { RESUME_RUNNING, /** - * Fired exactly once, when the VM first starts running. + * Fired when the VM resumed running. *
- * Fired after all devices reported success from {@link VMDevice#load(VMContext)}. + * Fired after {@link #RESUME_RUNNING} has been fired and handled by all devices. *
- * If a running VM is restored from a saved state, this event will not be fired. It is - * intended for initializing the VM state on boot, e.g. by loading initial executable - * code into memory. + * Allows device initialization that relies on all other devices having fully loaded. *
- * This is invoked from the worker thread running the VM.
+ * Typically this is used in combination with {@link #PAUSING}, to re-enable external
+ * interactions after VM state is guaranteed to be safe to modify again.
*/
- INITIALIZE,
+ RESUMED_RUNNING,
/**
* Fired when the device is disposed, either because the VM is disposed or the source
diff --git a/src/main/java/li/cil/oc2/common/bus/device/item/ByteBufferFlashMemoryVMDevice.java b/src/main/java/li/cil/oc2/common/bus/device/item/ByteBufferFlashMemoryVMDevice.java
index 4748c176..5c19d966 100644
--- a/src/main/java/li/cil/oc2/common/bus/device/item/ByteBufferFlashMemoryVMDevice.java
+++ b/src/main/java/li/cil/oc2/common/bus/device/item/ByteBufferFlashMemoryVMDevice.java
@@ -64,7 +64,7 @@ public final class ByteBufferFlashMemoryVMDevice extends IdentityProxy