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