Fix race condition in USB driver initialization and cleanup

This commit is contained in:
Cameron Gutman 2016-10-27 18:09:33 -07:00
parent e8f04f5a3b
commit 1c3b9a3859

View File

@ -114,13 +114,13 @@ public abstract class AbstractXboxController extends AbstractController {
return false;
}
// Report that we're added _before_ starting the input thread
notifyDeviceAdded();
// Start listening for controller input
inputThread = createInputThread();
inputThread.start();
// Now report we're added
notifyDeviceAdded();
return true;
}
@ -137,11 +137,11 @@ public abstract class AbstractXboxController extends AbstractController {
inputThread = null;
}
// Report the device removed
notifyDeviceRemoved();
// Close the USB connection
connection.close();
// Report the device removed
notifyDeviceRemoved();
}
protected abstract boolean handleRead(ByteBuffer buffer);