Skip to content

Commit 415911f

Browse files
committed
Fixed async lock
1 parent eafb9b7 commit 415911f

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

src/ImageWizard.Core/Locking/AsyncLock.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public AsyncLock()
2222
}
2323

2424
internal AsyncLock(object syncObject)
25-
: this()
2625
{
2726
_syncObj = syncObject;
2827
}

src/ImageWizard.Core/Locking/AsyncLockReleaser.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ namespace ImageWizard.Core.Locking;
1616
public class AsyncLockReleaser : IDisposable
1717
{
1818
private readonly AsyncLock _asyncLock;
19-
private readonly AsyncLockType? _type;
19+
private readonly AsyncLockType _type;
2020

21-
internal AsyncLockReleaser(AsyncLock asyncLock, AsyncLockType? type)
21+
internal AsyncLockReleaser(AsyncLock asyncLock, AsyncLockType type)
2222
{
2323
_asyncLock = asyncLock;
2424
_type = type;
2525
}
2626

27-
internal AsyncLockType? Type => _type;
27+
internal AsyncLockType Type => _type;
2828

2929
internal AsyncLock AsyncLock => _asyncLock;
3030

@@ -37,11 +37,10 @@ public void Dispose()
3737
return;
3838
}
3939

40-
if (_type != null)
41-
{
42-
_asyncLock.Release(_type.Value);
43-
}
44-
40+
_asyncLock.Release(_type);
41+
4542
_disposed = true;
43+
44+
GC.SuppressFinalize(this);
4645
}
4746
}

src/ImageWizard.Core/Locking/QueueExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static class QueueExtensions
1515
{
1616
public static TaskCompletionSource<T> Enqueue<T>(this Queue<TaskCompletionSource<T>> queue, CancellationToken cancellationToken)
1717
{
18-
TaskCompletionSource<T> item = new TaskCompletionSource<T>();
18+
TaskCompletionSource<T> item = new TaskCompletionSource<T>(TaskCreationOptions.RunContinuationsAsynchronously);
1919

2020
queue.Enqueue(item);
2121

src/ImageWizard.Tests/AsyncLockKeyTest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ public async Task WriterReaderSameKey()
4848
{
4949
AsyncLock<string> lockEntity = new AsyncLock<string>();
5050

51-
using var w1 = await lockEntity.WriterLockAsync("2");
51+
CancellationTokenSource s = new CancellationTokenSource();
52+
53+
using var w1 = await lockEntity.WriterLockAsync("2", s.Token);
5254

5355
await Assert.ThrowsAsync<TimeoutException>(()=> lockEntity.ReaderLockAsync("2").WaitAsync(TimeSpan.FromSeconds(1)));
5456
}

0 commit comments

Comments
 (0)