DotNext.Threading by .NET Foundation and Contributors

<PackageReference Include="DotNext.Threading" Version="4.12.0" />

 AsyncSharedLock

Represents a lock that can be acquired in exclusive or weak mode.
public long ConcurrencyLevel { get; }

Gets the maximum number of locks that can be obtained simultaneously.

public bool IsLockHeld { get; }

Indicates that the lock is acquired in exclusive or shared mode.

public bool IsStrongLockHeld { get; }

Indicates that the lock is acquired in exclusive mode.

public long RemainingCount { get; }

Gets the number of shared locks that can be acquired.

public AsyncSharedLock(long concurrencyLevel, bool limitedConcurrency = true)

Initializes a new shared lock.

public ValueTask AcquireAsync(bool strongLock, TimeSpan timeout, CancellationToken token = default)

Entres the lock asynchronously.

public ValueTask AcquireAsync(bool strongLock, CancellationToken token = default)

Entres the lock asynchronously.

public void Downgrade()

Releases the acquired weak lock or downgrade exclusive lock to the weak lock.

public void Release()

Release the acquired lock.

public bool TryAcquire(bool strongLock)

Attempts to obtain lock synchronously without blocking caller thread.

public ValueTask<bool> TryAcquireAsync(bool strongLock, TimeSpan timeout, CancellationToken token = default)

Attempts to enter the lock asynchronously, with an optional time-out.