arturobernalg commented on code in PR #728:
URL: 
https://github.com/apache/httpcomponents-client/pull/728#discussion_r2576566283


##########
httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncExecRuntime.java:
##########
@@ -282,10 +313,115 @@ public EndpointInfo getEndpointInfo() {
         return endpoint != null ? endpoint.getInfo() : null;
     }
 
+    private boolean tryAcquireSlot() {
+        if (sharedQueued == null) {
+            return true;
+        }
+        for (; ; ) {
+            final int q = sharedQueued.get();
+            if (q >= maxQueued) {
+                return false;
+            }
+            if (sharedQueued.compareAndSet(q, q + 1)) {
+                return true;
+            }
+        }
+    }
+
+    private void releaseSlot() {
+        if (sharedQueued != null) {
+            sharedQueued.decrementAndGet();
+        }
+    }
+
+    private AsyncClientExchangeHandler guard(final AsyncClientExchangeHandler 
h) {
+        return new AsyncClientExchangeHandler() {
+            private final AtomicBoolean done = new AtomicBoolean(false);
+
+            private void finish() {
+                if (done.compareAndSet(false, true)) {
+                    releaseSlot();
+                }
+            }
+
+            @Override
+            public void failed(final Exception cause) {
+                try {
+                    h.failed(cause);
+                } finally {
+                    finish();
+                }
+            }
+
+            @Override
+            public void cancel() {
+                try {
+                    h.cancel();
+                } finally {
+                    finish();
+                }
+            }
+
+            @Override
+            public void releaseResources() {

Review Comment:
   @ok2c  please do another pass



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to