-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switched lock provider to a more performant library
- Loading branch information
1 parent
5b708fa
commit 2a8b06f
Showing
3 changed files
with
23 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,36 @@ | ||
using System; | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using NeoSmart.AsyncLock; | ||
using AsyncKeyedLock; | ||
|
||
namespace EFCoreSecondLevelCacheInterceptor; | ||
|
||
/// <summary> | ||
/// Reader writer locking service | ||
/// </summary> | ||
public class LockProvider : ILockProvider | ||
public sealed class LockProvider : ILockProvider | ||
{ | ||
private readonly AsyncLock _lock = new(); | ||
private readonly AsyncNonKeyedLocker _lock = new(); | ||
|
||
/// <summary> | ||
/// Tries to enter the sync lock | ||
/// </summary> | ||
public IDisposable Lock(CancellationToken cancellationToken = default) => _lock.Lock(cancellationToken); | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public AsyncNonKeyedLockReleaser Lock(CancellationToken cancellationToken = default) => _lock.Lock(cancellationToken); | ||
|
||
/// <summary> | ||
/// Tries to enter the async lock | ||
/// </summary> | ||
public Task<IDisposable> LockAsync(CancellationToken cancellationToken = default) => | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public ValueTask<AsyncNonKeyedLockReleaser> LockAsync(CancellationToken cancellationToken = default) => | ||
_lock.LockAsync(cancellationToken); | ||
|
||
/// <summary> | ||
/// Disposes the lock | ||
/// </summary> | ||
public void Dispose() | ||
{ | ||
_lock.Dispose(); | ||
} | ||
} |