ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/SynchronousQueue.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/SynchronousQueue.java (file contents):
Revision 1.47 by dl, Wed Mar 2 17:15:26 2005 UTC vs.
Revision 1.48 by jsr166, Tue Apr 26 01:17:18 2005 UTC

# Line 39 | Line 39 | import java.util.*;
39   *
40   * <p>This class and its iterator implement all of the
41   * <em>optional</em> methods of the {@link Collection} and {@link
42 < * Iterator} interfaces.
42 > * Iterator} interfaces.
43   *
44   * <p>This class is a member of the
45   * <a href="{@docRoot}/../guide/collections/index.html">
# Line 116 | Line 116 | public class SynchronousQueue<E> extends
116       * in order to recover fairness settings when deserialized.
117       */
118      static abstract class WaitQueue implements java.io.Serializable {
119 <        /** Create, add, and return node for x */
119 >        /** Creates, adds, and returns node for x. */
120          abstract Node enq(Object x);
121 <        /** Remove and return node, or null if empty */
121 >        /** Removes and returns node, or null if empty. */
122          abstract Node deq();
123 <        /** Remove a cancelled node to avoid garbage retention. */
123 >        /** Removes a cancelled node to avoid garbage retention. */
124          abstract void unlink(Node node);
125 <        /** Return true if a cancelled node might be on queue */
125 >        /** Returns true if a cancelled node might be on queue. */
126          abstract boolean shouldUnlink(Node node);
127      }
128  
# Line 164 | Line 164 | public class SynchronousQueue<E> extends
164              while (p != null) {
165                  if (p == node) {
166                      Node next = p.next;
167 <                    if (trail == null)
167 >                    if (trail == null)
168                          head = next;
169                      else
170                          trail.next = next;
# Line 210 | Line 210 | public class SynchronousQueue<E> extends
210              while (p != null) {
211                  if (p == node) {
212                      Node next = p.next;
213 <                    if (trail == null)
213 >                    if (trail == null)
214                          head = next;
215                      else
216                          trail.next = next;
# Line 225 | Line 225 | public class SynchronousQueue<E> extends
225      /*
226       * Unlink the given node from consumer queue.  Called by cancelled
227       * (timeout, interrupt) waiters to avoid garbage retention in the
228 <     * absence of producers.
228 >     * absence of producers.
229       */
230      private void unlinkCancelledConsumer(Node node) {
231          // Use a form of double-check to avoid unnecessary locking and
# Line 234 | Line 234 | public class SynchronousQueue<E> extends
234          if (waitingConsumers.shouldUnlink(node)) {
235              qlock.lock();
236              try {
237 <                if (waitingConsumers.shouldUnlink(node))
237 >                if (waitingConsumers.shouldUnlink(node))
238                      waitingConsumers.unlink(node);
239              } finally {
240                  qlock.unlock();
# Line 250 | Line 250 | public class SynchronousQueue<E> extends
250          if (waitingProducers.shouldUnlink(node)) {
251              qlock.lock();
252              try {
253 <                if (waitingProducers.shouldUnlink(node))
253 >                if (waitingProducers.shouldUnlink(node))
254                      waitingProducers.unlink(node);
255              } finally {
256                  qlock.unlock();
257              }
258          }
259      }
260 <        
260 >
261      /**
262       * Nodes each maintain an item and handle waits and signals for
263       * getting and setting it. The class extends
# Line 308 | Line 308 | public class SynchronousQueue<E> extends
308           * Tries to cancel on interrupt; if so rethrowing,
309           * else setting interrupt state
310           */
311 <        private void checkCancellationOnInterrupt(InterruptedException ie)
311 >        private void checkCancellationOnInterrupt(InterruptedException ie)
312              throws InterruptedException {
313 <            if (release(CANCEL))
313 >            if (release(CANCEL))
314                  throw ie;
315              Thread.currentThread().interrupt();
316          }
# Line 458 | Line 458 | public class SynchronousQueue<E> extends
458              if (mustWait) {
459                  try {
460                      boolean x = node.waitForTake(nanos);
461 <                    if (!x)
461 >                    if (!x)
462                          unlinkCancelledProducer(node);
463                      return x;
464                  } catch (InterruptedException ex) {
# Line 547 | Line 547 | public class SynchronousQueue<E> extends
547              if (mustWait) {
548                  try {
549                      Object x = node.waitForPut(nanos);
550 <                    if (x == null)
550 >                    if (x == null)
551                          unlinkCancelledConsumer(node);
552                      return (E)x;
553                  } catch (InterruptedException ex) {
# Line 573 | Line 573 | public class SynchronousQueue<E> extends
573      * @param o the element to add.
574      * @return <tt>true</tt> if it was possible to add the element to
575      *         this queue, else <tt>false</tt>
576 <    * @throws NullPointerException if the specified element is <tt>null</tt>
576 >    * @throws NullPointerException if the specified element is <tt>null</tt>.
577      */
578      public boolean offer(E o) {
579          if (o == null) throw new NullPointerException();
# Line 626 | Line 626 | public class SynchronousQueue<E> extends
626      }
627  
628      /**
629 <     * Always returns <tt>true</tt>.
629 >     * Always returns <tt>true</tt>.
630       * A <tt>SynchronousQueue</tt> has no internal capacity.
631       * @return <tt>true</tt>
632       */
# Line 710 | Line 710 | public class SynchronousQueue<E> extends
710      }
711  
712      /**
713 <     * Always returns <tt>null</tt>.
713 >     * Always returns <tt>null</tt>.
714       * A <tt>SynchronousQueue</tt> does not return elements
715       * unless actively waited on.
716       * @return <tt>null</tt>
# Line 792 | Line 792 | public class SynchronousQueue<E> extends
792          return n;
793      }
794   }
795
796
797
798
799

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines