Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

binder: Invoke onTransportReady() in a round-robin fashion. #8835

Merged
merged 1 commit into from
Jan 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 17 additions & 3 deletions binder/src/main/java/io/grpc/binder/internal/BinderTransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
import io.grpc.internal.StatsTraceContext;
import io.grpc.internal.TimeProvider;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
Expand Down Expand Up @@ -186,6 +188,9 @@ protected enum TransportState {

protected final ConcurrentHashMap<Integer, Inbound<?>> ongoingCalls;

@GuardedBy("this")
private final LinkedHashSet<Integer> callIdsToNotifyWhenReady = new LinkedHashSet<>();

@GuardedBy("this")
protected Attributes attributes;

Expand Down Expand Up @@ -529,9 +534,18 @@ final void handleAcknowledgedBytes(long numBytes) {
logger.log(
Level.FINE,
"handleAcknowledgedBytes: Transmit Window No-Longer Full. Unblock calls: " + this);
// We're ready again, and need to poke any waiting transactions.
for (Inbound<?> inbound : ongoingCalls.values()) {
inbound.onTransportReady();

// The LinkedHashSet contract guarantees that an id already present in this collection will
// not lose its priority if we re-insert it here.
callIdsToNotifyWhenReady.addAll(ongoingCalls.keySet());

Iterator<Integer> i = callIdsToNotifyWhenReady.iterator();
while (isReady() && i.hasNext()) {
Inbound<?> inbound = ongoingCalls.get(i.next());
i.remove();
if (inbound != null) { // Calls can be removed out from under us.
inbound.onTransportReady();
}
}
}
}
Expand Down