2024-10-22 17:15:00 +02:00
--- a/net/minecraft/util/TickThrottler.java
+++ b/net/minecraft/util/TickThrottler.java
2024-12-13 20:30:07 +01:00
@@ -3,7 +_,7 @@
2024-10-22 17:15:00 +02:00
public class TickThrottler {
private final int incrementStep;
private final int threshold;
- private int count;
2024-12-13 20:30:07 +01:00
+ private final java.util.concurrent.atomic.AtomicInteger count = new java.util.concurrent.atomic.AtomicInteger(); // CraftBukkit - multithreaded field
2024-10-22 17:15:00 +02:00
2024-12-13 20:30:07 +01:00
public TickThrottler(int incrementStep, int threshold) {
this.incrementStep = incrementStep;
@@ -11,16 +_,31 @@
2024-10-22 17:15:00 +02:00
}
public void increment() {
2024-12-13 20:30:07 +01:00
- this.count = this.count + this.incrementStep;
2024-10-22 17:15:00 +02:00
+ this.count.addAndGet(this.incrementStep); // CraftBukkit - use thread-safe field access instead
}
public void tick() {
+ // CraftBukkit start
2024-12-11 22:26:55 +01:00
+ for (int val; (val = this.count.get()) > 0 && !this.count.compareAndSet(val, val - 1); ) ;
2024-10-22 17:15:00 +02:00
+ /* Use thread-safe field access instead
if (this.count > 0) {
2024-12-13 20:30:07 +01:00
this.count--;
2024-10-22 17:15:00 +02:00
}
+ */
+ // CraftBukkit end
}
public boolean isUnderThreshold() {
- return this.count < this.threshold;
+ // CraftBukkit start - use thread-safe field access instead
+ return this.count.get() < this.threshold;
2024-12-13 20:30:07 +01:00
+ }
2024-10-22 17:15:00 +02:00
+
+ public boolean isIncrementAndUnderThreshold() {
2024-12-11 22:26:55 +01:00
+ return this.isIncrementAndUnderThreshold(this.incrementStep, this.threshold);
2024-10-22 17:15:00 +02:00
+ }
+
+ public boolean isIncrementAndUnderThreshold(int incrementStep, int threshold) {
+ return this.count.addAndGet(incrementStep) < threshold;
+ // CraftBukkit end
2024-12-13 20:30:07 +01:00
}
2024-10-22 17:15:00 +02:00
}