mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-02 17:32:03 +01:00
30e4583dbe
By: Initial Source <noreply+automated@papermc.io>
53 lines
1.6 KiB
Diff
53 lines
1.6 KiB
Diff
--- a/net/minecraft/util/TickThrottler.java
|
|
+++ b/net/minecraft/util/TickThrottler.java
|
|
@@ -1,10 +1,14 @@
|
|
package net.minecraft.util;
|
|
|
|
+// CraftBukkit start
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
+// CraftBukkit end
|
|
+
|
|
public class TickThrottler {
|
|
|
|
private final int incrementStep;
|
|
private final int threshold;
|
|
- private int count;
|
|
+ private final AtomicInteger count = new AtomicInteger(); // CraftBukkit - multithreaded field
|
|
|
|
public TickThrottler(int increment, int threshold) {
|
|
this.incrementStep = increment;
|
|
@@ -12,17 +16,32 @@
|
|
}
|
|
|
|
public void increment() {
|
|
- 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
|
|
+ }
|
|
}
|