Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Commit

Permalink
Thread safety fix for async entity tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
windcolor-dev committed Sep 14, 2023
1 parent 32849fc commit 759ed9d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.util.List;
import com.google.common.collect.Lists;

import co.aikar.timings.SpigotTimings;
import ga.windpvp.windspigot.config.WindSpigotConfig;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.WorldServer;

Expand Down Expand Up @@ -40,12 +43,30 @@ public void tick() {
}

private void tickWorlds() {
// Cache world tick runnables if not cached already
this.cacheWorlds();

for (WorldTicker ticker : this.worldTickers) {
ticker.run();
}
// Cache world tick runnables if not cached already
this.cacheWorlds();

// Wait for entity tracking if async entity tracking takes this long
if (!WindSpigotConfig.disableTracking) {
for (WorldTicker ticker : this.worldTickers) {
try {
ticker.getLatch().waitTillZero();
} catch (InterruptedException e) {
e.printStackTrace();
}
ticker.getLatch().reset();
}
}

// Move BukkitScheduler stuff here so async entity tracking does not interfere
SpigotTimings.bukkitSchedulerTimer.startTiming(); // Spigot
// CraftBukkit start
MinecraftServer.getServer().server.getScheduler().mainThreadHeartbeat(MinecraftServer.getServer().at());
SpigotTimings.bukkitSchedulerTimer.stopTiming(); // Spigot

for (WorldTicker ticker : this.worldTickers) {
ticker.run();
}
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1035,10 +1035,11 @@ public void B() {

this.methodProfiler.c("levels");

SpigotTimings.bukkitSchedulerTimer.startTiming(); // Spigot
// CraftBukkit start
this.server.getScheduler().mainThreadHeartbeat(this.ticks);
SpigotTimings.bukkitSchedulerTimer.stopTiming(); // Spigot
// WindSpigot - move to WorldTickManager
// SpigotTimings.bukkitSchedulerTimer.startTiming(); // Spigot
// // CraftBukkit start
// this.server.getScheduler().mainThreadHeartbeat(this.ticks);
// SpigotTimings.bukkitSchedulerTimer.stopTiming(); // Spigot

// Run tasks that are waiting on processing
SpigotTimings.processQueueTimer.startTiming(); // Spigot
Expand Down

0 comments on commit 759ed9d

Please sign in to comment.