mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-06 18:50:51 +01:00
45 lines
1.6 KiB
Diff
45 lines
1.6 KiB
Diff
--- a/net/minecraft/util/TickThrottler.java
|
|
+++ b/net/minecraft/util/TickThrottler.java
|
|
@@ -3,7 +_,7 @@
|
|
public class TickThrottler {
|
|
private final int incrementStep;
|
|
private final int threshold;
|
|
- private int count;
|
|
+ private final java.util.concurrent.atomic.AtomicInteger count = new java.util.concurrent.atomic.AtomicInteger(); // CraftBukkit - multithreaded field
|
|
|
|
public TickThrottler(int incrementStep, int threshold) {
|
|
this.incrementStep = incrementStep;
|
|
@@ -11,16 +_,31 @@
|
|
}
|
|
|
|
public void increment() {
|
|
- this.count = this.count + this.incrementStep;
|
|
+ this.count.addAndGet(this.incrementStep); // CraftBukkit - use thread-safe field access instead
|
|
}
|
|
|
|
public void tick() {
|
|
+ // CraftBukkit start
|
|
+ for (int val; (val = this.count.get()) > 0 && !this.count.compareAndSet(val, val - 1); ) ;
|
|
+ /* Use thread-safe field access instead
|
|
if (this.count > 0) {
|
|
this.count--;
|
|
}
|
|
+ */
|
|
+ // CraftBukkit end
|
|
}
|
|
|
|
public boolean isUnderThreshold() {
|
|
- return this.count < this.threshold;
|
|
+ // CraftBukkit start - use thread-safe field access instead
|
|
+ return this.count.get() < this.threshold;
|
|
+ }
|
|
+
|
|
+ public boolean isIncrementAndUnderThreshold() {
|
|
+ return this.isIncrementAndUnderThreshold(this.incrementStep, this.threshold);
|
|
+ }
|
|
+
|
|
+ public boolean isIncrementAndUnderThreshold(int incrementStep, int threshold) {
|
|
+ return this.count.addAndGet(incrementStep) < threshold;
|
|
+ // CraftBukkit end
|
|
}
|
|
}
|