diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-09-02 09:01:12 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2021-09-02 09:01:12 -0500 |
| commit | 633bbe6f774fe6af4e5dace4b32bc7da91e5d75d (patch) | |
| tree | 8c34ba4918b85b8849d6df386e6b94f205ef788b /src/slskd/Application/SharedFileCache.cs | |
| parent | f564152d88a8ed2df72326c032c89889bdf211df (diff) | |
| download | slskd-633bbe6f774fe6af4e5dace4b32bc7da91e5d75d.tar.gz | |
atomically obtain or reject semaphore
Diffstat (limited to 'src/slskd/Application/SharedFileCache.cs')
| -rw-r--r-- | src/slskd/Application/SharedFileCache.cs | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/slskd/Application/SharedFileCache.cs b/src/slskd/Application/SharedFileCache.cs index e9ebeb66..a469de22 100644 --- a/src/slskd/Application/SharedFileCache.cs +++ b/src/slskd/Application/SharedFileCache.cs @@ -107,19 +107,17 @@ namespace slskd /// <returns>The operation context.</returns> public async Task FillAsync() { - if (SyncRoot.CurrentCount == 0) + // obtain the semaphore, or fail if it can't be obtained immediately, indicating that a scan is running. + if (!await SyncRoot.WaitAsync(millisecondsTimeout: 0)) { Log.Warning("Shared file scan rejected; scan is already in progress."); throw new ShareScanInProgressException("Shared files are already being scanned."); } - await Task.Yield(); - - await SyncRoot.WaitAsync(); - try { - // todo: don't do this, but rather build a new cache and then swap it in + await Task.Yield(); + ResetCache(); State.SetValue(state => state with { Filling = true, FillProgress = 0 }); |
