/** * Extracts element at current take position, advances, and signals. * Call only when holding lock. */ private Object extract() { final Object[] items = this.items; Object x = items[takeIndex]; items[takeIndex] = null; takeIndex = inc(takeIndex); --count; notFull.signal(); return x; }
/** * Inserts element at current put position, advances, and signals. * Call only when holding lock. */ private void insert(Object x) { items[putIndex] = x; putIndex = inc(putIndex); ++count; notEmpty.signal(); }
/** * Inserts element at current put position, advances, and signals. * Call only when holding lock. */ private void insert(Object x) { items[putIndex] = x; putIndex = inc(putIndex); ++count; notEmpty.signal(); }
/** * Inserts element at current put position, advances, and signals. * Call only when holding lock. */ private void insert(Object x) { items[putIndex] = x; putIndex = inc(putIndex); ++count; notEmpty.signal(); }
/** * Utility for remove and iterator.remove: Delete item at position i. * Call only when holding lock. */ void removeAt(int i) { final Object[] items = this.items; // if removing front item, just advance if (i == takeIndex) { items[takeIndex] = null; takeIndex = inc(takeIndex); } else { // slide over all others up through putIndex. for (;;) { int nexti = inc(i); if (nexti != putIndex) { items[i] = items[nexti]; i = nexti; } else { items[i] = null; putIndex = i; break; } } } --count; notFull.signal(); }
/** * Extracts element at current take position, advances, and signals. * Call only when holding lock. */ private Object extract() { final Object[] items = this.items; Object x = items[takeIndex]; items[takeIndex] = null; takeIndex = inc(takeIndex); --count; notFull.signal(); return x; }
/** * Utility for remove and iterator.remove: Delete item at position i. * Call only when holding lock. */ void removeAt(int i) { final Object[] items = this.items; // if removing front item, just advance if (i == takeIndex) { items[takeIndex] = null; takeIndex = inc(takeIndex); } else { // slide over all others up through putIndex. for (;;) { int nexti = inc(i); if (nexti != putIndex) { items[i] = items[nexti]; i = nexti; } else { items[i] = null; putIndex = i; break; } } } --count; notFull.signal(); }
/** * Extracts element at current take position, advances, and signals. * Call only when holding lock. */ private Object extract() { final Object[] items = this.items; Object x = items[takeIndex]; items[takeIndex] = null; takeIndex = inc(takeIndex); --count; notFull.signal(); return x; }
/** * Utility for remove and iterator.remove: Delete item at position i. * Call only when holding lock. */ void removeAt(int i) { final Object[] items = this.items; // if removing front item, just advance if (i == takeIndex) { items[takeIndex] = null; takeIndex = inc(takeIndex); } else { // slide over all others up through putIndex. for (;;) { int nexti = inc(i); if (nexti != putIndex) { items[i] = items[nexti]; i = nexti; } else { items[i] = null; putIndex = i; break; } } } --count; notFull.signal(); }
/** * Returns <tt>true</tt> if this queue contains the specified element. * More formally, returns <tt>true</tt> if and only if this queue contains * at least one element <tt>e</tt> such that <tt>o.equals(e)</tt>. * * @param o object to be checked for containment in this queue * @return <tt>true</tt> if this queue contains the specified element */ public boolean contains(Object o) { if (o == null) return false; final Object[] items = this.items; final ReentrantLock lock = this.lock; lock.lock(); try { int i = takeIndex; int k = 0; while (k++ < count) { if (o.equals(items[i])) return true; i = inc(i); } return false; } finally { lock.unlock(); } }
public Object next() { final ReentrantLock lock = ArrayBlockingQueue.this.lock; lock.lock(); try { if (nextIndex < 0) throw new NoSuchElementException(); lastRet = nextIndex; Object x = nextItem; nextIndex = inc(nextIndex); checkNext(); return x; } finally { lock.unlock(); } }
/** * Returns <tt>true</tt> if this queue contains the specified element. * More formally, returns <tt>true</tt> if and only if this queue contains * at least one element <tt>e</tt> such that <tt>o.equals(e)</tt>. * * @param o object to be checked for containment in this queue * @return <tt>true</tt> if this queue contains the specified element */ public boolean contains(Object o) { if (o == null) return false; final Object[] items = this.items; final ReentrantLock lock = this.lock; lock.lock(); try { int i = takeIndex; int k = 0; while (k++ < count) { if (o.equals(items[i])) return true; i = inc(i); } return false; } finally { lock.unlock(); } }
public Object next() { final ReentrantLock lock = ArrayBlockingQueue.this.lock; lock.lock(); try { if (nextIndex < 0) throw new NoSuchElementException(); lastRet = nextIndex; Object x = nextItem; nextIndex = inc(nextIndex); checkNext(); return x; } finally { lock.unlock(); } }
public Object next() { final ReentrantLock lock = ArrayBlockingQueue.this.lock; lock.lock(); try { if (nextIndex < 0) throw new NoSuchElementException(); lastRet = nextIndex; Object x = nextItem; nextIndex = inc(nextIndex); checkNext(); return x; } finally { lock.unlock(); } }
/** * Returns <tt>true</tt> if this queue contains the specified element. * More formally, returns <tt>true</tt> if and only if this queue contains * at least one element <tt>e</tt> such that <tt>o.equals(e)</tt>. * * @param o object to be checked for containment in this queue * @return <tt>true</tt> if this queue contains the specified element */ public boolean contains(Object o) { if (o == null) return false; final Object[] items = this.items; final ReentrantLock lock = this.lock; lock.lock(); try { int i = takeIndex; int k = 0; while (k++ < count) { if (o.equals(items[i])) return true; i = inc(i); } return false; } finally { lock.unlock(); } }
/** * Returns an array containing all of the elements in this queue, in * proper sequence. * * <p>The returned array will be "safe" in that no references to it are * maintained by this queue. (In other words, this method must allocate * a new array). The caller is thus free to modify the returned array. * * <p>This method acts as bridge between array-based and collection-based * APIs. * * @return an array containing all of the elements in this queue */ public Object[] toArray() { final Object[] items = this.items; final ReentrantLock lock = this.lock; lock.lock(); try { Object[] a = new Object[count]; int k = 0; int i = takeIndex; while (k < count) { a[k++] = items[i]; i = inc(i); } return a; } finally { lock.unlock(); } }
/** * Returns an array containing all of the elements in this queue, in * proper sequence. * * <p>The returned array will be "safe" in that no references to it are * maintained by this queue. (In other words, this method must allocate * a new array). The caller is thus free to modify the returned array. * * <p>This method acts as bridge between array-based and collection-based * APIs. * * @return an array containing all of the elements in this queue */ public Object[] toArray() { final Object[] items = this.items; final ReentrantLock lock = this.lock; lock.lock(); try { Object[] a = new Object[count]; int k = 0; int i = takeIndex; while (k < count) { a[k++] = items[i]; i = inc(i); } return a; } finally { lock.unlock(); } }
/** * Atomically removes all of the elements from this queue. * The queue will be empty after this call returns. */ public void clear() { final Object[] items = this.items; final ReentrantLock lock = this.lock; lock.lock(); try { int i = takeIndex; int k = count; while (k-- > 0) { items[i] = null; i = inc(i); } count = 0; putIndex = 0; takeIndex = 0; notFull.signalAll(); } finally { lock.unlock(); } }
/** * Atomically removes all of the elements from this queue. * The queue will be empty after this call returns. */ public void clear() { final Object[] items = this.items; final ReentrantLock lock = this.lock; lock.lock(); try { int i = takeIndex; int k = count; while (k-- > 0) { items[i] = null; i = inc(i); } count = 0; putIndex = 0; takeIndex = 0; notFull.signalAll(); } finally { lock.unlock(); } }
/** * Atomically removes all of the elements from this queue. * The queue will be empty after this call returns. */ public void clear() { final Object[] items = this.items; final ReentrantLock lock = this.lock; lock.lock(); try { int i = takeIndex; int k = count; while (k-- > 0) { items[i] = null; i = inc(i); } count = 0; putIndex = 0; takeIndex = 0; notFull.signalAll(); } finally { lock.unlock(); } }