Skip to content

Commit

Permalink
Fix file storage read lock (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
glucaci committed May 15, 2020
1 parent d6b0c6a commit 7b66fae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/Core/Transmission.Abstractions/AsyncLock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ internal async ValueTask<Releaser> LockAsync(CancellationToken cancellationToken

internal struct Releaser : IDisposable
{
internal static Releaser Empty = new Releaser(new AsyncLock());

private readonly AsyncLock _asyncLock;
private bool _isDisposed;

Expand Down
14 changes: 10 additions & 4 deletions src/Core/Transmission.Abstractions/FilesLock.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -35,13 +34,20 @@ internal static async ValueTask<Releaser> ReadLockAsync(
throw new ArgumentNullException(nameof(fileName));
}

Files.TryRemove(fileName, out AsyncLock asyncLock);
Debug.WriteLine(Files.Count);
return new Releaser(await asyncLock.LockAsync(cancellationToken));
if (Files.ContainsKey(fileName))
{
Files.TryRemove(fileName, out AsyncLock asyncLock);

return new Releaser(await asyncLock.LockAsync(cancellationToken));
}

return Releaser.Empty;
}

internal struct Releaser : IDisposable
{
internal static Releaser Empty = new Releaser(AsyncLock.Releaser.Empty);

private AsyncLock.Releaser _releaser;

internal Releaser(AsyncLock.Releaser releaser)
Expand Down

0 comments on commit 7b66fae

Please sign in to comment.