Skip to content

Commit

Permalink
Finish annotating the concurrent queues. (typetools#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpovirk authored Sep 6, 2023
1 parent 81d2dde commit 9674c43
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ public boolean offer(E e, long timeout, TimeUnit unit)
}
}

public E poll() {
public @Nullable E poll() {
final ReentrantLock lock = this.lock;
lock.lock();
try {
Expand All @@ -434,7 +434,7 @@ public E take() throws InterruptedException {
}
}

public E poll(long timeout, TimeUnit unit) throws InterruptedException {
public @Nullable E poll(long timeout, TimeUnit unit) throws InterruptedException {
long nanos = unit.toNanos(timeout);
final ReentrantLock lock = this.lock;
lock.lockInterruptibly();
Expand All @@ -450,7 +450,7 @@ public E poll(long timeout, TimeUnit unit) throws InterruptedException {
}
}

public E peek() {
public @Nullable E peek() {
final ReentrantLock lock = this.lock;
lock.lock();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.checkerframework.checker.signedness.qual.PolySigned;
import org.checkerframework.checker.signedness.qual.UnknownSignedness;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.framework.qual.AnnotatedFor;

import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
Expand Down Expand Up @@ -96,7 +97,8 @@
* @author Doug Lea
* @param <E> the type of elements held in this queue
*/
public class LinkedTransferQueue<E> extends AbstractQueue<E>
@AnnotatedFor("nullness")
public class LinkedTransferQueue<E extends Object> extends AbstractQueue<E>
implements TransferQueue<E>, java.io.Serializable {
private static final long serialVersionUID = -3223113410248163686L;

Expand Down Expand Up @@ -1298,14 +1300,14 @@ public E take() throws InterruptedException {
throw new InterruptedException();
}

public E poll(long timeout, TimeUnit unit) throws InterruptedException {
public @Nullable E poll(long timeout, TimeUnit unit) throws InterruptedException {
E e = xfer(null, false, TIMED, unit.toNanos(timeout));
if (e != null || !Thread.interrupted())
return e;
throw new InterruptedException();
}

public E poll() {
public @Nullable E poll() {
return xfer(null, false, NOW, 0L);
}

Expand Down Expand Up @@ -1350,7 +1352,7 @@ public Iterator<E> iterator() {
return new Itr();
}

public E peek() {
public @Nullable E peek() {
restartFromHead: for (;;) {
for (Node p = head; p != null;) {
Object item = p.item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ public E take() throws InterruptedException {
* specified waiting time elapses before an element is present
* @throws InterruptedException {@inheritDoc}
*/
public E poll(long timeout, TimeUnit unit) throws InterruptedException {
public @Nullable E poll(long timeout, TimeUnit unit) throws InterruptedException {
E e = transferer.transfer(null, true, unit.toNanos(timeout));
if (e != null || !Thread.interrupted())
return e;
Expand All @@ -924,7 +924,7 @@ public E poll(long timeout, TimeUnit unit) throws InterruptedException {
* @return the head of this queue, or {@code null} if no
* element is available
*/
public E poll() {
public @Nullable E poll() {
return transferer.transfer(null, true, 0);
}

Expand Down Expand Up @@ -1031,7 +1031,7 @@ public boolean retainAll(Collection<? extends @UnknownSignedness Object> c) {
*
* @return {@code null}
*/
public E peek() {
public @Nullable E peek() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

package java.util.concurrent;

import org.checkerframework.framework.qual.AnnotatedFor;

/**
* A {@link BlockingQueue} in which producers may wait for consumers
* to receive elements. A {@code TransferQueue} may be useful for
Expand Down Expand Up @@ -65,7 +67,8 @@
* @author Doug Lea
* @param <E> the type of elements held in this queue
*/
public interface TransferQueue<E> extends BlockingQueue<E> {
@AnnotatedFor("nullness")
public interface TransferQueue<E extends Object> extends BlockingQueue<E> {
/**
* Transfers the element to a waiting consumer immediately, if possible.
*
Expand Down

0 comments on commit 9674c43

Please sign in to comment.