From bbe6cdb052be982d33828e5ffa7fe499959789b2 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 23 Oct 2025 07:29:45 -0500 Subject: add semaphores --- src/slskd/Transfers/Downloads/DownloadService.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/Transfers/Downloads/DownloadService.cs b/src/slskd/Transfers/Downloads/DownloadService.cs index cdff2394..e480c70b 100644 --- a/src/slskd/Transfers/Downloads/DownloadService.cs +++ b/src/slskd/Transfers/Downloads/DownloadService.cs @@ -148,7 +148,19 @@ namespace slskd.Transfers.Downloads private ILogger Log { get; } = Serilog.Log.ForContext(); private IOptionsMonitor OptionsMonitor { get; } private EventBus EventBus { get; } - private ConcurrentDictionary Locks { get; } = new(); + + /// + /// Allow only one enqueue operation for a given user at a time. Entries are added on the fly if they + /// don't already exist, and a timer asynchronously cleans the dictionary up. + /// + private ConcurrentDictionary EnqueueSemaphores { get; } = []; + + /// + /// Synchronizes the cleanup process; after gaining exclusive access over the dictionary, checks each entry + /// to see if the containing semaphore can be obtained immediately. If so, it's not in use and is therefore + /// removed from the dictionary and discarded. + /// + private SemaphoreSlim EnqueueSemaphoreSyncRoot { get; } = new SemaphoreSlim(initialCount: 1, maxCount: 1); /// /// Adds the specified . Supersedes any existing record for the same file and username. -- cgit v1.2.3