Update network semaphore comments

This commit is contained in:
James Seibel
2024-09-17 07:40:28 -05:00
parent 840b0a7fe2
commit f7bf05b62f
2 changed files with 16 additions and 2 deletions
@@ -536,9 +536,15 @@ public class DhServerLevel extends AbstractDhLevel implements IDhServerLevel
@CheckForNull @CheckForNull
public FullDataSourceV2 fullDataSource; 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. <br>
* Reentrant Lock isn't used since it would allow the thread to lock on the same group. <br>
* 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); public final Semaphore requestAddSemaphore = new Semaphore(Short.MAX_VALUE, true);
/** @see DataSourceRequestGroup#requestAddSemaphore */
public final Semaphore requestRemoveSemaphore = new Semaphore(Short.MAX_VALUE, true); public final Semaphore requestRemoveSemaphore = new Semaphore(Short.MAX_VALUE, true);
} }
@@ -5,6 +5,7 @@ import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.config.types.ConfigEntry; import com.seibel.distanthorizons.core.config.types.ConfigEntry;
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2; import com.seibel.distanthorizons.core.dataObjects.fullData.sources.FullDataSourceV2;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector; 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.level.IDhClientLevel;
import com.seibel.distanthorizons.core.logging.ConfigBasedSpamLogger; import com.seibel.distanthorizons.core.logging.ConfigBasedSpamLogger;
import com.seibel.distanthorizons.core.network.exceptions.InvalidLevelException; import com.seibel.distanthorizons.core.network.exceptions.InvalidLevelException;
@@ -60,6 +61,13 @@ public abstract class AbstractFullDataNetworkRequestQueue implements IDebugRende
private volatile CompletableFuture<Void> closingFuture = null; private volatile CompletableFuture<Void> closingFuture = null;
protected final ConcurrentMap<Long, RequestQueueEntry> waitingTasksBySectionPos = new ConcurrentHashMap<>(); protected final ConcurrentMap<Long, RequestQueueEntry> 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. <br>
* Reentrant Lock isn't used since it would allow the thread to lock on the same group. <br>
* 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 Semaphore pendingTasksSemaphore = new Semaphore(Short.MAX_VALUE, true);
private final AtomicInteger finishedRequests = new AtomicInteger(); private final AtomicInteger finishedRequests = new AtomicInteger();