changeset 151:a6f18afacb4c

8077053: IllegalStateException at UART.read Summary: stopReading() is corrected Reviewed-by: alkonsta
author snazarki
date Mon, 06 Apr 2015 21:38:05 +0400
parents c004adba7229
children 33c00f148c64
files src/share/classes/com/oracle/dio/uart/impl/UARTImpl.java
diffstat 1 files changed, 13 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/oracle/dio/uart/impl/UARTImpl.java	Mon Apr 06 17:46:18 2015 +0300
+++ b/src/share/classes/com/oracle/dio/uart/impl/UARTImpl.java	Mon Apr 06 21:38:05 2015 +0400
@@ -587,14 +587,10 @@
         }
     }
 
-    /**
-     * Stops (cancels) the currently active reading session.
-      */
-    @Override
-    public void stopReading() throws IOException, UnavailableDeviceException, ClosedDeviceException{
-        checkOpen();
+
+    private void stopReading(boolean syncVer) throws IOException, UnavailableDeviceException, ClosedDeviceException {
         synchronized(synchReadLock) {
-            if (null != inRoundListener && !(inRoundListener instanceof InternalRoundListener) ) {
+            if (null != inRoundListener && syncVer == (inRoundListener instanceof InternalRoundListener) ) {
                 inRoundListener = null;
                 unsubscribe(UARTEvent.INPUT_DATA_AVAILABLE);
                 readBuffers[0] = readBuffers[1] = null;
@@ -605,6 +601,15 @@
     }
 
     /**
+     * Stops (cancels) the currently active reading session.
+      */
+    @Override
+    public void stopReading() throws IOException, UnavailableDeviceException, ClosedDeviceException{
+        checkOpen();
+        stopReading(false);
+    }
+
+    /**
      * Generates a break condition for the specified duration.
      */
     @Override
@@ -677,7 +682,7 @@
                             }catch(InterruptedException iE){
                                 throw new IOException();
                             } finally {
-                                stopReading();
+                                stopReading(true);
                             }
                     }
                 } // if !event thread