DotNext.Threading by .NET Foundation and Contributors

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

 AsyncReaderWriterLock

Represents asynchronous version of ReaderWriterLockSlim.
public struct LockStamp : IEquatable<LockStamp>

Represents lock stamp used for optimistic reading.

public long CurrentReadCount { get; }

Gets the total number of unique readers.

public bool IsReadLockHeld { get; }

Gets a value that indicates whether the read lock taken.

public bool IsWriteLockHeld { get; }

Gets a value that indicates whether the write lock taken.

public AsyncReaderWriterLock(int concurrencyLevel)

Initializes a new reader/writer lock.

Initializes a new reader/writer lock.

public void DowngradeFromWriteLock()

Downgrades the write lock to the read lock.

public ValueTask EnterReadLockAsync(TimeSpan timeout, CancellationToken token = default)

Enters the lock in read mode asynchronously.

Enters the lock in read mode asynchronously.

Enters the lock in write mode asynchronously.

public ValueTask EnterWriteLockAsync(TimeSpan timeout, CancellationToken token = default)

Enters the lock in write mode asynchronously.

public void Release()

Exits previously acquired mode.

public ValueTask StealWriteLockAsync(object reason, TimeSpan timeout, CancellationToken token = default)

Interrupts all pending callers in the queue and acquires write lock.

public ValueTask StealWriteLockAsync(object reason = null, CancellationToken token = default)

Interrupts all pending callers in the queue and acquires write lock.

public bool TryEnterReadLock()

Attempts to obtain reader lock synchronously without blocking caller thread.

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

Tries to enter the lock in read mode asynchronously, with an optional time-out.

public bool TryEnterWriteLock(ref LockStamp stamp)

Attempts to acquire write lock without blocking.

public bool TryEnterWriteLock()

Attempts to obtain writer lock synchronously without blocking caller thread.

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

Tries to enter the lock in write mode asynchronously, with an optional time-out.

Returns a stamp that can be validated later.

public ValueTask<bool> TryStealWriteLockAsync(object reason, TimeSpan timeout, CancellationToken token = default)

Interrupts all pending callers in the queue and acquires write lock.

public bool TryUpgradeToWriteLock()

Tries to upgrade the read lock to the write lock synchronously without blocking of the caller.

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

Tries to upgrade the read lock to the write lock asynchronously.

Upgrades the read lock to the write lock asynchronously.

Upgrades the read lock to the write lock asynchronously.

public bool Validate(ref LockStamp stamp)

Returns true if the lock has not been exclusively acquired since issuance of the given stamp.