src/share/classes/java/util/concurrent/Exchanger.java

Print this page

        

@@ -277,10 +277,11 @@
      * opportunistically subclasses AtomicReference to represent the
      * hole.  So get() returns hole, and compareAndSet CAS'es value
      * into hole.  This class cannot be parameterized as "V" because
      * of the use of non-V CANCEL sentinels.
      */
+    @SuppressWarnings("serial")
     private static final class Node extends AtomicReference<Object> {
         /** The element offered by the Thread creating this node. */
         public final Object item;
 
         /** The Thread waiting to be signalled; null until waiting. */

@@ -301,10 +302,11 @@
      * padding adds noticeable space, all slots are created only on
      * demand, and there will be more than one of them only when it
      * would improve throughput more than enough to outweigh using
      * extra space.
      */
+    @SuppressWarnings("serial")
     private static final class Slot extends AtomicReference<Object> {
         // Improve likelihood of isolation on <= 64 byte cache lines
         long q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, qa, qb, qc, qd, qe;
     }
 

@@ -614,17 +616,18 @@
      * @param x the object to exchange
      * @return the object provided by the other thread
      * @throws InterruptedException if the current thread was
      *         interrupted while waiting
      */
+    @SuppressWarnings("unchecked")
     public V exchange(V x) throws InterruptedException {
         if (!Thread.interrupted()) {
-            Object v = doExchange((x == null) ? NULL_ITEM : x, false, 0);
-            if (v == NULL_ITEM)
+            Object o = doExchange((x == null) ? NULL_ITEM : x, false, 0);
+            if (o == NULL_ITEM)
                 return null;
-            if (v != CANCEL)
-                return (V)v;
+            if (o != CANCEL)
+                return (V)o;
             Thread.interrupted(); // Clear interrupt status on IE throw
         }
         throw new InterruptedException();
     }
 

@@ -668,19 +671,20 @@
      * @throws InterruptedException if the current thread was
      *         interrupted while waiting
      * @throws TimeoutException if the specified waiting time elapses
      *         before another thread enters the exchange
      */
+    @SuppressWarnings("unchecked")
     public V exchange(V x, long timeout, TimeUnit unit)
         throws InterruptedException, TimeoutException {
         if (!Thread.interrupted()) {
-            Object v = doExchange((x == null) ? NULL_ITEM : x,
+            Object o = doExchange((x == null) ? NULL_ITEM : x,
                                   true, unit.toNanos(timeout));
-            if (v == NULL_ITEM)
+            if (o == NULL_ITEM)
                 return null;
-            if (v != CANCEL)
-                return (V)v;
+            if (o != CANCEL)
+                return (V)o;
             if (!Thread.interrupted())
                 throw new TimeoutException();
         }
         throw new InterruptedException();
     }