public E poll() {
// 队列为空返回null
final AtomicInteger count = this.count;
if (count.get() == 0)
return null;
// 获取出队锁对象
E x = null;
int c = -1;
final ReentrantLock takeLock = this.takeLock;
takeLock.lock();
try {
if (count.get() > 0) {
// 队列不空,则出队并递减计数器
x = dequeue();
c = count.getAndDecrement();
// 出队后队列不为空,则唤醒其他入队线程
if (c > 1)
notEmpty.signal();
}
} finally {
takeLock.unlock();
}
// 出队前队列满,则出队后队列有空隙,唤醒其他入队线程
if (c == capacity)
signalNotFull();
return x;
}