[cvs] / jsr166 / src / main / java / util / concurrent / SynchronousQueue.java Repository:
ViewVC logotype

Diff of /jsr166/src/main/java/util/concurrent/SynchronousQueue.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.55, Mon Aug 1 15:26:40 2005 UTC revision 1.56, Wed Aug 3 18:57:28 2005 UTC
# Line 47  Line 47 
47   * Java Collections Framework</a>.   * Java Collections Framework</a>.
48   *   *
49   * @since 1.5   * @since 1.5
50   * @author Doug Lea   * @author Doug Lea and Bill Scherer and Michael Scott
51   * @param <E> the type of elements held in this collection   * @param <E> the type of elements held in this collection
52   */   */
53  public class SynchronousQueue<E> extends AbstractQueue<E>  public class SynchronousQueue<E> extends AbstractQueue<E>
# Line 98  Line 98 
98       *     of further adaptations.       *     of further adaptations.
99       *  2. SynchronousQueues must block threads waiting to become       *  2. SynchronousQueues must block threads waiting to become
100       *     fulfilled.       *     fulfilled.
101       *  3. Nodes/threads that have been cancelled due to timeouts       *  3. Support for cancellation via timeout and interrupts,
102       *     or interruptions are cleaned out of the lists to       *     including cleaning out cancelled nodes/threads
103       *     avoid garbage retention and memory depletion.       *     from lists to avoid garbage retention and memory depletion.
104       *       *
105       * Blocking is mainly accomplished using LockSupport park/unpark,       * Blocking is mainly accomplished using LockSupport park/unpark,
106       * except that nodes that appear to be the next ones to become       * except that nodes that appear to be the next ones to become
# Line 156  Line 156 
156      /**      /**
157       * The number of times to spin before blocking in timed waits.       * The number of times to spin before blocking in timed waits.
158       * The value is empirically derived -- it works well across a       * The value is empirically derived -- it works well across a
159       * variety of processors and OSes. Emprically, the best value       * variety of processors and OSes. Empirically, the best value
160       * seems not to vary with number of CPUs (beyond 2) so is just       * seems not to vary with number of CPUs (beyond 2) so is just
161       * a constant.       * a constant.
162       */       */
# Line 430  Line 430 
430           */           */
431          boolean shouldSpin(SNode s) {          boolean shouldSpin(SNode s) {
432              SNode h = head;              SNode h = head;
433              return (h == null || h == s || isFulfilling(h.mode));              return (h == s || h == null || isFulfilling(h.mode));
434          }          }
435    
436          /**          /**
# Line 522  Line 522 
522              boolean isCancelled() {              boolean isCancelled() {
523                  return item == this;                  return item == this;
524              }              }
525    
526                /**
527                 * Return true if this node is known to be off the queue
528                 * because its next pointer has been forgotten due to
529                 * an advanceHead operation.
530                 */
531                boolean isOffList() {
532                    return next == this;
533                }
534          }          }
535    
536          /** Head of queue */          /** Head of queue */
# Line 638  Line 647 
647                          return null;                          return null;
648                      }                      }
649    
650                      if (s.next != s) {              // not already unlinked                      if (!s.isOffList()) {           // not already unlinked
651                          advanceHead(t, s);          // unlink                          advanceHead(t, s);          // unlink if head
652                          if (x != null)              // and forget fields                          if (x != null)              // and forget fields
653                              s.item = s;                              s.item = s;
654                          s.waiter = null;                          s.waiter = null;
# Line 764  Line 773 
773      /**      /**
774       * The transferer. Set only in constructor, but cannot be declared       * The transferer. Set only in constructor, but cannot be declared
775       * as final without further complicating serialization.  Since       * as final without further complicating serialization.  Since
776       * this is accessed only once per public method, there isn't a       * this is accessed only at most once per public method, there
777       * noticeable performance penalty for using volatile instead of       * isn't a noticeable performance penalty for using volatile
778       * final here.       * instead of final here.
779       */       */
780      private transient volatile Transferer transferer;      private transient volatile Transferer transferer;
781    

Legend:
Removed from v.1.55  
changed lines
  Added in v.1.56

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8