diff --git a/core/src/main/java/com/seibel/distanthorizons/core/level/DhServerLevel.java b/core/src/main/java/com/seibel/distanthorizons/core/level/DhServerLevel.java
index 4ea422400..f146d42b7 100644
--- a/core/src/main/java/com/seibel/distanthorizons/core/level/DhServerLevel.java
+++ b/core/src/main/java/com/seibel/distanthorizons/core/level/DhServerLevel.java
@@ -536,9 +536,15 @@ public class DhServerLevel extends AbstractDhLevel implements IDhServerLevel
@CheckForNull
public FullDataSourceV2 fullDataSource;
- // Maybe there's a better way to do synchronization, but this should suffice
- // Why not something like ReentrantReadWriteLock: locks should not be bound to threads
+ /**
+ * These semaphores prevent a given thread from accidentally locking on the same group
+ * multiple times, as the semaphore is tied to the given thread.
+ * Reentrant Lock isn't used since it would allow the thread to lock on the same group.
+ * the Short.MAX_VALUE is just a very large number that should be larger than the number of
+ * threads we'll have.
+ */
public final Semaphore requestAddSemaphore = new Semaphore(Short.MAX_VALUE, true);
+ /** @see DataSourceRequestGroup#requestAddSemaphore */
public final Semaphore requestRemoveSemaphore = new Semaphore(Short.MAX_VALUE, true);
}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/multiplayer/client/AbstractFullDataNetworkRequestQueue.java b/core/src/main/java/com/seibel/distanthorizons/core/multiplayer/client/AbstractFullDataNetworkRequestQueue.java
index 1eb2fac5c..b162ba5ad 100644
--- a/core/src/main/java/com/seibel/distanthorizons/core/multiplayer/client/AbstractFullDataNetworkRequestQueue.java
+++ b/core/src/main/java/com/seibel/distanthorizons/core/multiplayer/client/AbstractFullDataNetworkRequestQueue.java
@@ -5,6 +5,7 @@ import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.config.types.ConfigEntry;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
+import com.seibel.distanthorizons.core.level.DhServerLevel;
import com.seibel.distanthorizons.core.level.IDhClientLevel;
import com.seibel.distanthorizons.core.logging.ConfigBasedSpamLogger;
import com.seibel.distanthorizons.core.network.exceptions.InvalidLevelException;
@@ -60,6 +61,13 @@ public abstract class AbstractFullDataNetworkRequestQueue implements IDebugRende
private volatile CompletableFuture closingFuture = null;
protected final ConcurrentMap waitingTasksBySectionPos = new ConcurrentHashMap<>();
+ /**
+ * This semaphore prevents a given thread from accidentally locking on the same group
+ * multiple times, as the semaphore is tied to the given thread.
+ * Reentrant Lock isn't used since it would allow the thread to lock on the same group.
+ * the Short.MAX_VALUE is just a very large number that should be larger than the number of
+ * threads we'll have.
+ */
private final Semaphore pendingTasksSemaphore = new Semaphore(Short.MAX_VALUE, true);
private final AtomicInteger finishedRequests = new AtomicInteger();