1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

[CI skip] Changed internal profiler flag to a volatile boolean

This commit is contained in:
TheBusyBiscuit 2021-01-19 10:01:28 +01:00
parent 4075c51975
commit 9840a550ce
2 changed files with 16 additions and 9 deletions

View File

@ -349,7 +349,7 @@
<dependency>
<groupId>com.github.TheBusyBiscuit</groupId>
<artifactId>CS-CoreLib2</artifactId>
<version>0.29.3</version>
<version>0.29.6</version>
<scope>compile</scope>
</dependency>
<dependency>

View File

@ -8,7 +8,6 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
@ -68,7 +67,15 @@ public class SlimefunProfiler {
*/
private final PerformanceRating[] performanceRatings = PerformanceRating.values();
private final AtomicBoolean isProfiling = new AtomicBoolean(false);
/**
* This boolean marks whether we are currently profiling or not.
*/
private volatile boolean isProfiling = false;
/**
* This {@link AtomicInteger} holds the amount of blocks that still need to be
* profiled.
*/
private final AtomicInteger queued = new AtomicInteger(0);
private long totalElapsedTime;
@ -89,7 +96,7 @@ public class SlimefunProfiler {
* This method starts the profiling, data from previous runs will be cleared.
*/
public void start() {
isProfiling.set(true);
isProfiling = true;
queued.set(0);
timings.clear();
}
@ -100,7 +107,7 @@ public class SlimefunProfiler {
* @return A timestamp, best fed back into {@link #closeEntry(Location, SlimefunItem, long)}
*/
public long newEntry() {
if (!isProfiling.get()) {
if (!isProfiling) {
return 0;
}
@ -119,7 +126,7 @@ public class SlimefunProfiler {
* The amount of entries that should be scheduled. Can be negative
*/
public void scheduleEntries(int amount) {
if (isProfiling.get()) {
if (isProfiling) {
queued.getAndAdd(amount);
}
}
@ -162,7 +169,7 @@ public class SlimefunProfiler {
* This stops the profiling.
*/
public void stop() {
isProfiling.set(false);
isProfiling = false;
if (SlimefunPlugin.instance() == null || !SlimefunPlugin.instance().isEnabled()) {
// Slimefun has been disabled
@ -177,7 +184,7 @@ public class SlimefunProfiler {
int iterations = 4000;
// Wait for all timing results to come in
while (!isProfiling.get() && queued.get() > 0) {
while (!isProfiling && queued.get() > 0) {
try {
/**
* Since we got more than one Thread in our pool,
@ -203,7 +210,7 @@ public class SlimefunProfiler {
}
}
if (isProfiling.get() && queued.get() > 0) {
if (isProfiling && queued.get() > 0) {
// Looks like the next profiling has already started, abort!
return;
}