Skip to content

Commit

Permalink
Merge branch 'connector-2024.1.x'
Browse files Browse the repository at this point in the history
# Conflicts:
#	pom.xml
  • Loading branch information
smcvb committed Nov 6, 2024
2 parents 5b16f79 + cc96708 commit 471d8f0
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.grpc.stub.ClientCallStreamObserver;

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantLock;

/**
* Lock-based synchronized implementation of a {@link ClientCallStreamObserver}. Acts as a wrapper of another {@code
Expand All @@ -30,7 +31,7 @@
public class SynchronizedRequestStream<T> extends ClientCallStreamObserver<T> {

private final ClientCallStreamObserver<T> delegate;
private final AtomicBoolean lock = new AtomicBoolean(false);
private final ReentrantLock lock = new ReentrantLock();
private final AtomicBoolean halfClosed = new AtomicBoolean(false);

/**
Expand Down Expand Up @@ -100,15 +101,13 @@ public void onCompleted() {
}

private void inLock(Runnable action) {
while (!lock.compareAndSet(false, true)) {
Thread.yield();
}
try {
lock.lock();
if (!halfClosed.get()) {
action.run();
}
} finally {
lock.set(false);
lock.unlock();
}
}
}

0 comments on commit 471d8f0

Please sign in to comment.