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.75 by jsr166, Thu Dec 29 22:37:31 2016 UTC vs.
Revision 1.76 by jsr166, Tue Mar 28 00:27:21 2017 UTC

# Line 294 | Line 294 | public class DelayQueue<E extends Delaye
294      }
295  
296      /**
297     * Returns first element only if it is expired.
298     * Used only by drainTo.  Call only when holding lock.
299     */
300    private E peekExpired() {
301        // assert lock.isHeldByCurrentThread();
302        E first = q.peek();
303        return (first == null || first.getDelay(NANOSECONDS) > 0) ?
304            null : first;
305    }
306
307    /**
297       * @throws UnsupportedOperationException {@inheritDoc}
298       * @throws ClassCastException            {@inheritDoc}
299       * @throws NullPointerException          {@inheritDoc}
300       * @throws IllegalArgumentException      {@inheritDoc}
301       */
302      public int drainTo(Collection<? super E> c) {
303 <        Objects.requireNonNull(c);
315 <        if (c == this)
316 <            throw new IllegalArgumentException();
317 <        final ReentrantLock lock = this.lock;
318 <        lock.lock();
319 <        try {
320 <            int n = 0;
321 <            for (E e; (e = peekExpired()) != null;) {
322 <                c.add(e);       // In this order, in case add() throws.
323 <                q.poll();
324 <                ++n;
325 <            }
326 <            return n;
327 <        } finally {
328 <            lock.unlock();
329 <        }
303 >        return drainTo(c, Integer.MAX_VALUE);
304      }
305  
306      /**
# Line 345 | Line 319 | public class DelayQueue<E extends Delaye
319          lock.lock();
320          try {
321              int n = 0;
322 <            for (E e; n < maxElements && (e = peekExpired()) != null;) {
323 <                c.add(e);       // In this order, in case add() throws.
322 >            for (E first;
323 >                 n < maxElements
324 >                     && (first = q.peek()) != null
325 >                     && first.getDelay(NANOSECONDS) <= 0;) {
326 >                c.add(first);   // In this order, in case add() throws.
327                  q.poll();
328                  ++n;
329              }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines