Clean up worker thread join logic a bit and fire resuming event immediately to avoid performance issues/race conditions for some devices (e.g. network cards).
This commit is contained in:
@@ -2,7 +2,7 @@ package li.cil.oc2.common.bus.device.item;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import li.cil.oc2.api.bus.device.vm.event.VMResumingRunningEvent;
|
||||
import li.cil.oc2.api.bus.device.vm.event.VMResumedRunningEvent;
|
||||
import li.cil.oc2.common.util.Location;
|
||||
import li.cil.sedna.api.device.BlockDevice;
|
||||
import li.cil.sedna.device.block.ByteBufferBlockDevice;
|
||||
@@ -39,7 +39,7 @@ public final class HardDriveVMDeviceWithInitialData extends HardDriveVMDevice {
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void handleResumingRunningEvent(final VMResumingRunningEvent event) {
|
||||
public void handleResumedRunningEvent(final VMResumedRunningEvent event) {
|
||||
if (copyJob != null) {
|
||||
try {
|
||||
copyJob.get();
|
||||
|
||||
@@ -167,9 +167,7 @@ public abstract class AbstractVirtualMachine implements VirtualMachine {
|
||||
private void joinWorkerThread() {
|
||||
if (runner != null) {
|
||||
try {
|
||||
state.context.postEvent(new VMPausingEvent());
|
||||
runner.join();
|
||||
runner.scheduleResumeEvent();
|
||||
} catch (final Throwable e) {
|
||||
LOGGER.error(e);
|
||||
runner = null;
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package li.cil.oc2.common.vm;
|
||||
|
||||
import li.cil.ceres.api.Serialized;
|
||||
import li.cil.oc2.api.bus.device.vm.event.VMInitializationException;
|
||||
import li.cil.oc2.api.bus.device.vm.event.VMInitializingEvent;
|
||||
import li.cil.oc2.api.bus.device.vm.event.VMResumedRunningEvent;
|
||||
import li.cil.oc2.api.bus.device.vm.event.VMResumingRunningEvent;
|
||||
import li.cil.oc2.api.bus.device.vm.event.*;
|
||||
import li.cil.oc2.common.Constants;
|
||||
import li.cil.oc2.common.bus.RPCDeviceBusAdapter;
|
||||
import li.cil.oc2.common.vm.context.global.GlobalVMContext;
|
||||
@@ -40,7 +37,7 @@ public class VMRunner implements Runnable {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
private boolean firedResumeEvent;
|
||||
private boolean firedResumedRunningEvent;
|
||||
@Serialized private boolean firedInitializationEvent;
|
||||
@Serialized private Component runtimeError;
|
||||
|
||||
@@ -57,10 +54,6 @@ public class VMRunner implements Runnable {
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public void scheduleResumeEvent() {
|
||||
firedResumeEvent = false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Component getRuntimeError() {
|
||||
return runtimeError;
|
||||
@@ -79,14 +72,20 @@ public class VMRunner implements Runnable {
|
||||
}
|
||||
|
||||
public void join() throws Throwable {
|
||||
if (lastSchedule != null) {
|
||||
try {
|
||||
lastSchedule.get();
|
||||
} catch (final InterruptedException e) {
|
||||
// We do not mind this.
|
||||
} catch (final ExecutionException e) {
|
||||
throw e.getCause();
|
||||
context.postEvent(new VMPausingEvent());
|
||||
try {
|
||||
if (lastSchedule != null) {
|
||||
try {
|
||||
lastSchedule.get();
|
||||
} catch (final InterruptedException e) {
|
||||
// We do not mind this.
|
||||
} catch (final ExecutionException e) {
|
||||
throw e.getCause();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
context.postEvent(new VMResumingRunningEvent());
|
||||
firedResumedRunningEvent = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,9 +135,8 @@ public class VMRunner implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
if (!firedResumeEvent) {
|
||||
firedResumeEvent = true;
|
||||
context.postEvent(new VMResumingRunningEvent());
|
||||
if (!firedResumedRunningEvent) {
|
||||
firedResumedRunningEvent = true;
|
||||
context.postEvent(new VMResumedRunningEvent());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user