changeset 182:b69e341f7472

8085976: SPICompositeMessage.transfer() returns 1-element array for delay/write-only SPICompositeMessages Summary: return array contains read results only Reviewed-by: alkonsta
author snazarki
date Mon, 08 Jun 2015 16:48:02 +0300
parents f3b2ea714446
children 60ec35bb6d26
files src/share/classes/com/oracle/dio/spibus/impl/SPICompositeMessageImpl.java
diffstat 1 files changed, 14 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/oracle/dio/spibus/impl/SPICompositeMessageImpl.java	Mon Jun 08 15:17:30 2015 +0300
+++ b/src/share/classes/com/oracle/dio/spibus/impl/SPICompositeMessageImpl.java	Mon Jun 08 16:48:02 2015 +0300
@@ -27,6 +27,7 @@
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
+import java.util.Vector;
 
 import com.oracle.dio.utils.ExceptionMessage;
 
@@ -38,7 +39,7 @@
 
 final class SPICompositeMessageImpl implements SPICompositeMessage {
 
-    private ArrayList<Message> messageList = new ArrayList<>();
+    private final ArrayList<Message> messageList = new ArrayList<>();
 
     private boolean isAlreadyTransferedOnce;
 
@@ -48,6 +49,9 @@
     // delay between operations
     private int delay;
 
+    // number of messages to read
+    private int rxMsgs;
+
     private class Message {
         ByteBuffer tx, rx;
         int skip, delay;
@@ -92,6 +96,10 @@
                 );
             }
         }
+
+        if (null != message.rx) {
+            rxMsgs++;
+        }
     }
 
     /**
@@ -131,7 +139,7 @@
         return append(src,skip,dst);
     }
 
-    private SPICompositeMessage append(ByteBuffer src, int skip, ByteBuffer dst)  throws IOException, ClosedDeviceException {
+    private synchronized SPICompositeMessage append(ByteBuffer src, int skip, ByteBuffer dst)  throws IOException, ClosedDeviceException {
         Message message = new Message(src, skip, dst, delay);
         check(message);
         messageList.add(message);
@@ -154,8 +162,6 @@
 
     @Override
     public int[] transfer() throws IOException, UnavailableDeviceException, ClosedDeviceException {
-        int bytesRead[];
-
         // global handle lock to prevent access from other threads.
         synchronized (device.getHandle()) {
             /* Forbid adding more messages to this combined message */
@@ -163,26 +169,21 @@
             if (0 == messageList.size()) {
                 return null;
             }
-
             int transaction = device.beginTransaction();
-
             try {
                 final int size = messageList.size();
-                bytesRead = new int[size];
-
-                for (int i = 0; i < size; i++) {
+                int[] bytesRead = new int[size];
+                for (int i = 0, j = 0; i < size; i++) {
                     Message message = messageList.get(i);
                     int res = device.transfer(message.tx, message.skip, message.rx, transaction);
                     if (null != message.rx) {
-                        bytesRead[i] = res;
+                        bytesRead[j++] = res;
                     }
                 }
-
+                return bytesRead;
             } finally {
                 device.endTransaction(transaction);
             }
-
         }
-        return bytesRead;
     }
 }