diff options
| author | JP Dillingham <jp@dillingham.me> | 2025-10-23 07:29:45 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2025-10-23 07:29:45 -0500 |
| commit | bbe6cdb052be982d33828e5ffa7fe499959789b2 (patch) | |
| tree | c1295d1b839d0a9ff8cbb0bf0500c9ec23f5c293 | |
| parent | bdacfba1a18b081758e695160b69919c5a236947 (diff) | |
| download | slskd-bbe6cdb052be982d33828e5ffa7fe499959789b2.tar.gz | |
add semaphores
| -rw-r--r-- | src/slskd/Transfers/Downloads/DownloadService.cs | 14 |
1 files changed, 13 insertions, 1 deletions
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<DownloadService>(); private IOptionsMonitor<Options> OptionsMonitor { get; } private EventBus EventBus { get; } - private ConcurrentDictionary<string, bool> Locks { get; } = new(); + + /// <summary> + /// 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. + /// </summary> + private ConcurrentDictionary<string, SemaphoreSlim> EnqueueSemaphores { get; } = []; + + /// <summary> + /// 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. + /// </summary> + private SemaphoreSlim EnqueueSemaphoreSyncRoot { get; } = new SemaphoreSlim(initialCount: 1, maxCount: 1); /// <summary> /// Adds the specified <paramref name="transfer"/>. Supersedes any existing record for the same file and username. |
