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

Comparing jsr166/src/main/java/util/concurrent/DelayQueue.java (file contents):
Revision 1.56 by jsr166, Mon Jun 27 21:01:06 2011 UTC vs.
Revision 1.57 by jsr166, Sun Jul 3 06:04:06 2011 UTC

# Line 461 | Line 461 | public class DelayQueue<E extends Delaye
461      }
462  
463      /**
464 +     * Identity-based version for use in Itr.remove
465 +     */
466 +    void removeEQ(Object o) {
467 +        final ReentrantLock lock = this.lock;
468 +        lock.lock();
469 +        try {
470 +            for (Iterator<E> it = q.iterator(); it.hasNext(); ) {
471 +                if (o == it.next()) {
472 +                    it.remove();
473 +                    break;
474 +                }
475 +            }
476 +        } finally {
477 +            lock.unlock();
478 +        }
479 +    }
480 +
481 +    /**
482       * Returns an iterator over all the elements (both expired and
483       * unexpired) in this queue. The iterator does not return the
484       * elements in any particular order.
# Line 483 | Line 501 | public class DelayQueue<E extends Delaye
501       */
502      private class Itr implements Iterator<E> {
503          final Object[] array; // Array of all elements
504 <        int cursor;           // index of next element to return;
504 >        int cursor;           // index of next element to return
505          int lastRet;          // index of last element, or -1 if no such
506  
507          Itr(Object[] array) {
# Line 506 | Line 524 | public class DelayQueue<E extends Delaye
524          public void remove() {
525              if (lastRet < 0)
526                  throw new IllegalStateException();
527 <            Object x = array[lastRet];
527 >            removeEQ(array[lastRet]);
528              lastRet = -1;
511            // Traverse underlying queue to find == element,
512            // not just a .equals element.
513            lock.lock();
514            try {
515                for (Iterator<E> it = q.iterator(); it.hasNext(); ) {
516                    if (it.next() == x) {
517                        it.remove();
518                        return;
519                    }
520                }
521            } finally {
522                lock.unlock();
523            }
529          }
530      }
531  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines