提交 cf3a32aa 编写于 作者: D dl

7107516: LinkedBlockingQueue/Deque.drainTo(Collection, int) returns...

7107516: LinkedBlockingQueue/Deque.drainTo(Collection, int) returns 'maxElements' if its value is negative
Reviewed-by: chegar, mduigou, dholmes
上级 c7b72ac3
...@@ -742,6 +742,8 @@ public class LinkedBlockingDeque<E> ...@@ -742,6 +742,8 @@ public class LinkedBlockingDeque<E>
throw new NullPointerException(); throw new NullPointerException();
if (c == this) if (c == this)
throw new IllegalArgumentException(); throw new IllegalArgumentException();
if (maxElements <= 0)
return 0;
final ReentrantLock lock = this.lock; final ReentrantLock lock = this.lock;
lock.lock(); lock.lock();
try { try {
......
...@@ -332,7 +332,7 @@ public class LinkedBlockingQueue<E> extends AbstractQueue<E> ...@@ -332,7 +332,7 @@ public class LinkedBlockingQueue<E> extends AbstractQueue<E>
// Note: convention in all put/take/etc is to preset local var // Note: convention in all put/take/etc is to preset local var
// holding count negative to indicate failure unless set. // holding count negative to indicate failure unless set.
int c = -1; int c = -1;
Node<E> node = new Node(e); Node<E> node = new Node<E>(e);
final ReentrantLock putLock = this.putLock; final ReentrantLock putLock = this.putLock;
final AtomicInteger count = this.count; final AtomicInteger count = this.count;
putLock.lockInterruptibly(); putLock.lockInterruptibly();
...@@ -412,7 +412,7 @@ public class LinkedBlockingQueue<E> extends AbstractQueue<E> ...@@ -412,7 +412,7 @@ public class LinkedBlockingQueue<E> extends AbstractQueue<E>
if (count.get() == capacity) if (count.get() == capacity)
return false; return false;
int c = -1; int c = -1;
Node<E> node = new Node(e); Node<E> node = new Node<E>(e);
final ReentrantLock putLock = this.putLock; final ReentrantLock putLock = this.putLock;
putLock.lock(); putLock.lock();
try { try {
...@@ -728,6 +728,8 @@ public class LinkedBlockingQueue<E> extends AbstractQueue<E> ...@@ -728,6 +728,8 @@ public class LinkedBlockingQueue<E> extends AbstractQueue<E>
throw new NullPointerException(); throw new NullPointerException();
if (c == this) if (c == this)
throw new IllegalArgumentException(); throw new IllegalArgumentException();
if (maxElements <= 0)
return 0;
boolean signalNotFull = false; boolean signalNotFull = false;
final ReentrantLock takeLock = this.takeLock; final ReentrantLock takeLock = this.takeLock;
takeLock.lock(); takeLock.lock();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册