Skip to content

Commit 498b971

Browse files
committed
Use TryDequeue for queue
1 parent 2519316 commit 498b971

File tree

3 files changed

+3
-13
lines changed

3 files changed

+3
-13
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
using AsyncKeyLock.Benchmarks;
22
using BenchmarkDotNet.Running;
33

4-
BenchmarkRunner.Run<BenchmarkSimpleWriterLock>();
4+
BenchmarkRunner.Run<BenchmarkSimpleKeyLock>();

src/AsyncKeyLock/AsyncLock.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,8 @@ private void WriterRelease()
170170
//no running writer lock?
171171
if (_isWriterRunning == false)
172172
{
173-
while (_waitingReaders.Count > 0)
173+
while (_waitingReaders.TryDequeue(out var taskSource))
174174
{
175-
var taskSource = _waitingReaders.Dequeue();
176-
177175
bool result = taskSource.TrySetResult(new ReaderReleaser(this, false));
178176

179177
if (result)
@@ -186,10 +184,8 @@ private void WriterRelease()
186184

187185
private void StartNextWaitingWriter()
188186
{
189-
while (_waitingWriters.Count > 0)
187+
while (_waitingWriters.TryDequeue(out var taskSource))
190188
{
191-
var taskSource = _waitingWriters.Dequeue();
192-
193189
bool result = taskSource.TrySetResult(new WriterReleaser(this, false));
194190

195191
if (result == true)

src/AsyncKeyLock/AsyncLock~.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ public AsyncLock(int maxPoolSize = 64)
2121
/// <summary>
2222
/// GetAsyncLock
2323
/// </summary>
24-
/// <param name="key"></param>
25-
/// <returns></returns>
2624
private AsyncLock GetAsyncLock(TKey key)
2725
{
2826
if (_locks.TryGetValue(key, out AsyncLock? asyncLock) == false)
@@ -52,8 +50,6 @@ private AsyncLock GetAsyncLock(TKey key)
5250
/// <summary>
5351
/// ReaderLockAsync
5452
/// </summary>
55-
/// <param name="key"></param>
56-
/// <returns></returns>
5753
public Task<ReaderReleaser> ReaderLockAsync(TKey key, CancellationToken cancellation = default)
5854
{
5955
lock (_locks)
@@ -65,8 +61,6 @@ public Task<ReaderReleaser> ReaderLockAsync(TKey key, CancellationToken cancella
6561
/// <summary>
6662
/// WriterLockAsync
6763
/// </summary>
68-
/// <param name="key"></param>
69-
/// <returns></returns>
7064
public Task<WriterReleaser> WriterLockAsync(TKey key, CancellationToken cancellation = default)
7165
{
7266
lock (_locks)

0 commit comments

Comments
 (0)