changeset 45:8472c11f06d8

8056170: SPIDevice.writeAndRead(ByteBuffer, int, ByteBuffer) is not blocking Reviewed-by: jld Contributed-by: alexey.karaksin@oracle.com
author alkonsta
date Mon, 15 Sep 2014 17:51:26 +0400
parents 306a4efd2ff7
children c4e318929675
files src/share/classes/com/oracle/dio/spibus/impl/SPISlaveImpl.java
diffstat 1 files changed, 15 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/oracle/dio/spibus/impl/SPISlaveImpl.java	Thu Sep 11 13:40:27 2014 -0400
+++ b/src/share/classes/com/oracle/dio/spibus/impl/SPISlaveImpl.java	Mon Sep 15 17:51:26 2014 +0400
@@ -471,6 +471,13 @@
         final boolean count_recv = null != dst;
         final boolean combined = (0 != skip || (null != dst && null != src && dst.remaining() != src.remaining()));
         Vector<Runnable> localActions;
+
+        /* synchronized allows to avoid IllegaStateException for the case when transfer()
+           is called while previous operation is incomplete.
+           sync on handle to avoid dead lock on close() since close is synchronized on this instance.
+        */
+        synchronized(handle){
+
         synchronized(this) {
             localActions = pendingActions;
         }
@@ -505,17 +512,15 @@
                     }
                 }
 
-                // synchronized allows to avoid IllegaStateException for the case when transfer() is called while previous operation is incomplete.
-                // sync on handle to avoid dead lock on close() since close is synchronized on this instance.
-                synchronized(handle) {
-                    try {
-                        conditionalLock();
-                         writeAndRead0(toSend, toRecv);
-                    } finally {
-                        conditionalUnlock();
-                    }
+
+                try {
+                    conditionalLock();
+                     writeAndRead0(toSend, toRecv);
+                } finally {
+                    conditionalUnlock();
                 }
 
+
                 if (count_recv) {
                     xfered += (null == toRecv) ? 0 : toRecv.remaining();
                 } else {
@@ -585,7 +590,7 @@
                 }
             }
         }
-
+        }//synchronized(handle)
         return xfered;
     }