use of java.util.concurrent.locks.ReentrantLock in project XobotOS by xamarin.
the class LinkedBlockingDeque method takeFirst.
public E takeFirst() throws InterruptedException {
final ReentrantLock lock = this.lock;
lock.lock();
try {
E x;
while ((x = unlinkFirst()) == null) notEmpty.await();
return x;
} finally {
lock.unlock();
}
}
use of java.util.concurrent.locks.ReentrantLock in project XobotOS by xamarin.
the class LinkedBlockingDeque method toString.
public String toString() {
final ReentrantLock lock = this.lock;
lock.lock();
try {
Node<E> p = first;
if (p == null)
return "[]";
StringBuilder sb = new StringBuilder();
sb.append('[');
for (; ; ) {
E e = p.item;
sb.append(e == this ? "(this Collection)" : e);
p = p.next;
if (p == null)
return sb.append(']').toString();
sb.append(',').append(' ');
}
} finally {
lock.unlock();
}
}
use of java.util.concurrent.locks.ReentrantLock in project XobotOS by xamarin.
the class LinkedBlockingDeque method pollFirst.
public E pollFirst() {
final ReentrantLock lock = this.lock;
lock.lock();
try {
return unlinkFirst();
} finally {
lock.unlock();
}
}
use of java.util.concurrent.locks.ReentrantLock in project XobotOS by xamarin.
the class LinkedBlockingDeque method offerFirst.
/**
* @throws NullPointerException {@inheritDoc}
*/
public boolean offerFirst(E e) {
if (e == null)
throw new NullPointerException();
Node<E> node = new Node<E>(e);
final ReentrantLock lock = this.lock;
lock.lock();
try {
return linkFirst(node);
} finally {
lock.unlock();
}
}
use of java.util.concurrent.locks.ReentrantLock in project XobotOS by xamarin.
the class LinkedBlockingDeque method drainTo.
/**
* @throws UnsupportedOperationException {@inheritDoc}
* @throws ClassCastException {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
* @throws IllegalArgumentException {@inheritDoc}
*/
public int drainTo(Collection<? super E> c, int maxElements) {
if (c == null)
throw new NullPointerException();
if (c == this)
throw new IllegalArgumentException();
final ReentrantLock lock = this.lock;
lock.lock();
try {
int n = Math.min(maxElements, count);
for (int i = 0; i < n; i++) {
// In this order, in case add() throws.
c.add(first.item);
unlinkFirst();
}
return n;
} finally {
lock.unlock();
}
}
Aggregations