This is an automated email from the ASF dual-hosted git repository.

merlimat pushed a commit to branch branch-4.18
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git

commit fd151877115fe60ef49ea83cb83cf996fbb3c15a
Author: Matteo Merli <[email protected]>
AuthorDate: Tue Jul 14 08:25:29 2026 -0700

    Add spin-wait hint to BlockingMpscQueue producer-side busy loops (#4831)
    
    (cherry picked from commit f1d7cc16f3ef5ca2644fd516a0dea7fe4c2a1fdb)
---
 .../org/apache/bookkeeper/common/collections/BlockingMpscQueue.java | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git 
a/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/collections/BlockingMpscQueue.java
 
b/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/collections/BlockingMpscQueue.java
index 56d9627e84..d19eb96243 100644
--- 
a/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/collections/BlockingMpscQueue.java
+++ 
b/bookkeeper-common/src/main/java/org/apache/bookkeeper/common/collections/BlockingMpscQueue.java
@@ -34,11 +34,14 @@ public class BlockingMpscQueue<T> extends MpscArrayQueue<T> 
implements BlockingQ
 
     @Override
     public void put(T e) throws InterruptedException {
+        int idleCounter = 0;
         while (!this.relaxedOffer(e)) {
             // Do busy-spin loop
             if (Thread.interrupted()) {
                 throw new InterruptedException();
             }
+
+            idleCounter = WAIT_STRATEGY.idle(idleCounter);
         }
     }
 
@@ -46,6 +49,7 @@ public class BlockingMpscQueue<T> extends MpscArrayQueue<T> 
implements BlockingQ
     public boolean offer(T e, long timeout, TimeUnit unit) throws 
InterruptedException {
         long absoluteEndTime = System.nanoTime() + unit.toNanos(timeout);
 
+        int idleCounter = 0;
         while (!this.relaxedOffer(e)) {
             // Do busy-spin loop
 
@@ -56,6 +60,8 @@ public class BlockingMpscQueue<T> extends MpscArrayQueue<T> 
implements BlockingQ
             if (Thread.interrupted()) {
                 throw new InterruptedException();
             }
+
+            idleCounter = WAIT_STRATEGY.idle(idleCounter);
         }
 
         return true;

Reply via email to