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

Comparing jsr166/src/main/java/util/concurrent/LinkedBlockingQueue.java (file contents):
Revision 1.112 by jsr166, Mon Jan 8 20:20:38 2018 UTC vs.
Revision 1.113 by jsr166, Tue Jan 30 19:00:33 2018 UTC

# Line 294 | Line 294 | public class LinkedBlockingQueue<E> exte
294       */
295      public void put(E e) throws InterruptedException {
296          if (e == null) throw new NullPointerException();
297 <        // Note: convention in all put/take/etc is to preset local var
298 <        // holding count negative to indicate failure unless set.
299 <        int c = -1;
300 <        Node<E> node = new Node<E>(e);
297 >        final int c;
298 >        final Node<E> node = new Node<E>(e);
299          final ReentrantLock putLock = this.putLock;
300          final AtomicInteger count = this.count;
301          putLock.lockInterruptibly();
# Line 338 | Line 336 | public class LinkedBlockingQueue<E> exte
336  
337          if (e == null) throw new NullPointerException();
338          long nanos = unit.toNanos(timeout);
339 <        int c = -1;
339 >        final int c;
340          final ReentrantLock putLock = this.putLock;
341          final AtomicInteger count = this.count;
342          putLock.lockInterruptibly();
# Line 376 | Line 374 | public class LinkedBlockingQueue<E> exte
374          final AtomicInteger count = this.count;
375          if (count.get() == capacity)
376              return false;
377 <        int c = -1;
378 <        Node<E> node = new Node<E>(e);
377 >        final int c;
378 >        final Node<E> node = new Node<E>(e);
379          final ReentrantLock putLock = this.putLock;
380          putLock.lock();
381          try {
382 <            if (count.get() < capacity) {
383 <                enqueue(node);
384 <                c = count.getAndIncrement();
385 <                if (c + 1 < capacity)
386 <                    notFull.signal();
387 <            }
382 >            if (count.get() == capacity)
383 >                return false;
384 >            enqueue(node);
385 >            c = count.getAndIncrement();
386 >            if (c + 1 < capacity)
387 >                notFull.signal();
388          } finally {
389              putLock.unlock();
390          }
391          if (c == 0)
392              signalNotEmpty();
393 <        return c >= 0;
393 >        return true;
394      }
395  
396      public E take() throws InterruptedException {
397 <        E x;
398 <        int c = -1;
397 >        final E x;
398 >        final int c;
399          final AtomicInteger count = this.count;
400          final ReentrantLock takeLock = this.takeLock;
401          takeLock.lockInterruptibly();
# Line 418 | Line 416 | public class LinkedBlockingQueue<E> exte
416      }
417  
418      public E poll(long timeout, TimeUnit unit) throws InterruptedException {
419 <        E x = null;
420 <        int c = -1;
419 >        final E x;
420 >        final int c;
421          long nanos = unit.toNanos(timeout);
422          final AtomicInteger count = this.count;
423          final ReentrantLock takeLock = this.takeLock;
# Line 446 | Line 444 | public class LinkedBlockingQueue<E> exte
444          final AtomicInteger count = this.count;
445          if (count.get() == 0)
446              return null;
447 <        E x = null;
448 <        int c = -1;
447 >        final E x;
448 >        final int c;
449          final ReentrantLock takeLock = this.takeLock;
450          takeLock.lock();
451          try {
452 <            if (count.get() > 0) {
453 <                x = dequeue();
454 <                c = count.getAndDecrement();
455 <                if (c > 1)
456 <                    notEmpty.signal();
457 <            }
452 >            if (count.get() == 0)
453 >                return null;
454 >            x = dequeue();
455 >            c = count.getAndDecrement();
456 >            if (c > 1)
457 >                notEmpty.signal();
458          } finally {
459              takeLock.unlock();
460          }
# Line 466 | Line 464 | public class LinkedBlockingQueue<E> exte
464      }
465  
466      public E peek() {
467 +        final AtomicInteger count = this.count;
468          if (count.get() == 0)
469              return null;
470          final ReentrantLock takeLock = this.takeLock;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines