From 53e22af02dfd3355eeda74c31164ee236b1cc19e Mon Sep 17 00:00:00 2001 From: Yash Mayya Date: Thu, 23 Jan 2025 18:50:52 +0530 Subject: [PATCH] Revert use of AtomicInteger in AdjustableSemaphore --- .../concurrency/AdjustableSemaphore.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/pinot-common/src/main/java/org/apache/pinot/common/concurrency/AdjustableSemaphore.java b/pinot-common/src/main/java/org/apache/pinot/common/concurrency/AdjustableSemaphore.java index f0e405d7fc8..b6a3408e49a 100644 --- a/pinot-common/src/main/java/org/apache/pinot/common/concurrency/AdjustableSemaphore.java +++ b/pinot-common/src/main/java/org/apache/pinot/common/concurrency/AdjustableSemaphore.java @@ -20,7 +20,6 @@ import com.google.common.base.Preconditions; import java.util.concurrent.Semaphore; -import java.util.concurrent.atomic.AtomicInteger; /** @@ -28,16 +27,16 @@ */ public class AdjustableSemaphore extends Semaphore { - private final AtomicInteger _totalPermits; + private volatile int _totalPermits; public AdjustableSemaphore(int permits) { super(permits); - _totalPermits = new AtomicInteger(permits); + _totalPermits = permits; } public AdjustableSemaphore(int permits, boolean fair) { super(permits, fair); - _totalPermits = new AtomicInteger(permits); + _totalPermits = permits; } /** @@ -45,12 +44,12 @@ public AdjustableSemaphore(int permits, boolean fair) { */ public void setPermits(int permits) { Preconditions.checkArgument(permits > 0, "Permits must be a positive integer"); - if (permits < _totalPermits.get()) { - reducePermits(_totalPermits.get() - permits); - } else if (permits > _totalPermits.get()) { - release(permits - _totalPermits.get()); + if (permits < _totalPermits) { + reducePermits(_totalPermits - permits); + } else if (permits > _totalPermits) { + release(permits - _totalPermits); } - _totalPermits.set(permits); + _totalPermits = permits; } /** @@ -58,6 +57,6 @@ public void setPermits(int permits) { * {@link #availablePermits()}). */ public int getTotalPermits() { - return _totalPermits.get(); + return _totalPermits; } }