File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed
androidTest/java/com/hoho/android/usbserial
main/java/com/hoho/android/usbserial/util Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -1485,6 +1485,17 @@ public void IoManager() throws Exception {
14851485 assertFalse ("iomanager threads" , usb .hasIoManagerThreads ());
14861486 assertNull (usb .ioManager );
14871487 assertEquals (SerialInputOutputManager .State .STOPPED , ioManager .getState ());
1488+
1489+ usb .open ();
1490+ ioManager = usb .ioManager ;
1491+ assertEquals (SerialInputOutputManager .State .RUNNING , usb .ioManager .getState ());
1492+ usb .serialPort .close (); // stop before ioManager
1493+ for (int i = 0 ; i < 100 && usb .hasIoManagerThreads (); i ++) {
1494+ Thread .sleep (1 );
1495+ }
1496+ assertFalse ("iomanager threads" , usb .hasIoManagerThreads ());
1497+ assertEquals (SerialInputOutputManager .State .STOPPED , usb .ioManager .getState ());
1498+
14881499 SerialInputOutputManager .DEBUG = false ;
14891500 }
14901501
Original file line number Diff line number Diff line change @@ -183,7 +183,7 @@ public void start() {
183183 public void stop () {
184184 if (mState .compareAndSet (State .RUNNING , State .STOPPING )) {
185185 synchronized (mWriteBufferLock ) {
186- mWriteBufferLock .notifyAll (); // Wake up any waiting thread to check the stop condition
186+ mWriteBufferLock .notifyAll (); // wake up write thread to check the stop condition
187187 }
188188 Log .i (TAG , "Stop requested" );
189189 }
@@ -250,10 +250,12 @@ void runRead() {
250250 }
251251 notifyErrorListener (e );
252252 } finally {
253- if (! mState .compareAndSet (State .RUNNING , State .STOPPING )) {
254- if ( mState . compareAndSet ( State . STOPPING , State . STOPPED ) ) {
255- Log . i ( TAG , "runRead: Stopped mState=" + getState ());
253+ if (mState .compareAndSet (State .RUNNING , State .STOPPING )) {
254+ synchronized ( mWriteBufferLock ) {
255+ mWriteBufferLock . notifyAll (); // wake up write thread to check the stop condition
256256 }
257+ } else if (mState .compareAndSet (State .STOPPING , State .STOPPED )) {
258+ Log .i (TAG , "runRead: Stopped mState=" + getState ());
257259 }
258260 }
259261 }
You can’t perform that action at this time.
0 commit comments