core: Replace AtomicInteger.updateAndGet with compareAndSet

updateAndGet is only available in API level 24+. It is unclear why
AnimalSniffer didn't detect this.

This was noticed when doing the import, but the Android CI has also been
failing because of it.
This commit is contained in:
Eric Anderson 2022-12-01 11:09:40 -08:00 committed by GitHub
parent 78415f55d3
commit b51cd9fd99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 3 deletions

View File

@ -225,9 +225,13 @@ abstract class RetriableStream<ReqT> implements ClientStream {
@Nullable // returns null when cancelled
private Substream createSubstream(int previousAttemptCount, boolean isTransparentRetry) {
// increment only when >= 0, i.e. not cancelled
if (inFlightSubStreams.updateAndGet(value -> value < 0 ? value : value + 1) < 0) {
return null;
}
int inFlight;
do {
inFlight = inFlightSubStreams.get();
if (inFlight < 0) {
return null;
}
} while (!inFlightSubStreams.compareAndSet(inFlight, inFlight + 1));
Substream sub = new Substream(previousAttemptCount);
// one tracer per substream
final ClientStreamTracer bufferSizeTracer = new BufferSizeTracer(sub);