Skip to content

Commit

Permalink
Using LinkedBlockingQueue for Android 12
Browse files Browse the repository at this point in the history
  • Loading branch information
Flewp committed Nov 22, 2024
1 parent 6a413e2 commit e0f6762
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.List;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicReference;

/**
Expand Down Expand Up @@ -149,9 +150,18 @@ public long getBatchNumber() {
}

private class ConcurrentOperationQueue {
private final Queue<UIThreadOperation> mQueue = new ConcurrentLinkedQueue<>();
private final Queue<UIThreadOperation> mQueue;
@Nullable private UIThreadOperation mPeekedOperation = null;

ConcurrentOperationQueue() {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.S || Build.VERSION.SDK_INT == Build.VERSION_CODES.S_V2) {
// Android 12's ConcurrentLinkedQueue is flaky, use LinkedBlockingQueue instead.
mQueue = new LinkedBlockingQueue<>();
} else {
mQueue = new ConcurrentLinkedQueue<>();
}
}

@AnyThread
boolean isEmpty() {
return mQueue.isEmpty() && mPeekedOperation == null;
Expand Down

0 comments on commit e0f6762

Please sign in to comment.