Class AsyncReaderWriterLock
Represents asynchronous version of ReaderWriterLockSlim.
Inherited Members
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public class AsyncReaderWriterLock : QueuedSynchronizer, ISynchronizer, IAsyncDisposable
Remarks
This lock doesn't support recursion.
Constructors
| Improve this Doc View SourceAsyncReaderWriterLock()
Initializes a new reader/writer lock.
Declaration
public AsyncReaderWriterLock()
Properties
| Improve this Doc View SourceCurrentReadCount
Gets the total number of unique readers.
Declaration
public long CurrentReadCount { get; }
Property Value
| Type | Description |
|---|---|
| Int64 |
IsReadLockHeld
Gets a value that indicates whether the read lock taken.
Declaration
public bool IsReadLockHeld { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
IsUpgradeableReadLockHeld
Gets a value that indicates whether the current upgradeable read lock taken.
Declaration
public bool IsUpgradeableReadLockHeld { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
IsWriteLockHeld
Gets a value that indicates whether the write lock taken.
Declaration
public bool IsWriteLockHeld { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
Methods
| Improve this Doc View SourceDisposeAsync()
Disposes this lock asynchronously and gracefully.
Declaration
public ValueTask DisposeAsync()
Returns
| Type | Description |
|---|---|
| ValueTask | The task representing graceful shutdown of this lock. |
Remarks
If this lock is not acquired then the method just completes synchronously. Otherwise, it waits for calling of ExitReadLock(), method.
EnterReadLockAsync(CancellationToken)
Enters the lock in read mode asynchronously.
Declaration
public Task EnterReadLockAsync(CancellationToken token)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | token | The token that can be used to abort lock acquisition. |
Returns
| Type | Description |
|---|---|
| Task | The task representing acquisition operation. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Time-out value is negative. |
| ObjectDisposedException | This object has been disposed. |
EnterReadLockAsync(TimeSpan, CancellationToken)
Enters the lock in read mode asynchronously.
Declaration
public Task EnterReadLockAsync(TimeSpan timeout, CancellationToken token = default(CancellationToken))
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | timeout | The interval to wait for the lock. |
| CancellationToken | token | The token that can be used to abort lock acquisition. |
Returns
| Type | Description |
|---|---|
| Task | The task representing acquisition operation. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Time-out value is negative. |
| ObjectDisposedException | This object has been disposed. |
| TimeoutException | The lock cannot be acquired during the specified amount of time. |
EnterUpgradeableReadLockAsync(CancellationToken)
Enters the lock in upgradeable mode asynchronously.
Declaration
public Task EnterUpgradeableReadLockAsync(CancellationToken token)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | token | The token that can be used to abort lock acquisition. |
Returns
| Type | Description |
|---|---|
| Task | The task representing lock acquisition operation. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Time-out value is negative. |
| ObjectDisposedException | This object has been disposed. |
EnterUpgradeableReadLockAsync(TimeSpan, CancellationToken)
Enters the lock in upgradeable mode asynchronously.
Declaration
public Task EnterUpgradeableReadLockAsync(TimeSpan timeout, CancellationToken token = default(CancellationToken))
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | timeout | The interval to wait for the lock. |
| CancellationToken | token | The token that can be used to abort lock acquisition. |
Returns
| Type | Description |
|---|---|
| Task | The task representing lock acquisition operation. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Time-out value is negative. |
| ObjectDisposedException | This object has been disposed. |
| TimeoutException | The lock cannot be acquired during the specified amount of time. |
EnterWriteLockAsync(CancellationToken)
Enters the lock in write mode asynchronously.
Declaration
public Task EnterWriteLockAsync(CancellationToken token)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | token | The token that can be used to abort lock acquisition. |
Returns
| Type | Description |
|---|---|
| Task | The task representing lock acquisition operation. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Time-out value is negative. |
| ObjectDisposedException | This object has been disposed. |
EnterWriteLockAsync(TimeSpan, CancellationToken)
Enters the lock in write mode asynchronously.
Declaration
public Task EnterWriteLockAsync(TimeSpan timeout, CancellationToken token = default(CancellationToken))
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | timeout | The interval to wait for the lock. |
| CancellationToken | token | The token that can be used to abort lock acquisition. |
Returns
| Type | Description |
|---|---|
| Task | The task representing lock acquisition operation. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Time-out value is negative. |
| ObjectDisposedException | This object has been disposed. |
| TimeoutException | The lock cannot be acquired during the specified amount of time. |
ExitReadLock()
Exits read mode.
Declaration
public void ExitReadLock()
Remarks
Exiting from the lock is synchronous non-blocking operation. Lock acquisition is an asynchronous operation.
Exceptions
| Type | Condition |
|---|---|
| SynchronizationLockException | The caller has not entered the lock in read mode. |
| ObjectDisposedException | This object has been disposed. |
ExitUpgradeableReadLock()
Exits upgradeable mode.
Declaration
public void ExitUpgradeableReadLock()
Remarks
Exiting from the lock is synchronous non-blocking operation. Lock acquisition is an asynchronous operation.
Exceptions
| Type | Condition |
|---|---|
| SynchronizationLockException | The caller has not entered the lock in upgradeable mode. |
| ObjectDisposedException | This object has been disposed. |
ExitWriteLock()
Exits write mode.
Declaration
public void ExitWriteLock()
Remarks
Exiting from the lock is synchronous non-blocking operation. Lock acquisition is an asynchronous operation.
Exceptions
| Type | Condition |
|---|---|
| SynchronizationLockException | The caller has not entered the lock in write mode. |
| ObjectDisposedException | This object has been disposed. |
TryEnterReadLock()
Attempts to obtain reader lock synchronously without blocking caller thread.
Declaration
public bool TryEnterReadLock()
Returns
| Type | Description |
|---|---|
| Boolean | true if lock is taken successfuly; otherwise, false. |
Exceptions
| Type | Condition |
|---|---|
| ObjectDisposedException | This object has been disposed. |
TryEnterReadLockAsync(TimeSpan)
Tries to enter the lock in read mode asynchronously, with an optional time-out.
Declaration
public Task<bool> TryEnterReadLockAsync(TimeSpan timeout)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | timeout | The interval to wait for the lock. |
Returns
| Type | Description |
|---|---|
| Task<Boolean> | true if the caller entered read mode; otherwise, false. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Time-out value is negative. |
| ObjectDisposedException | This object has been disposed. |
TryEnterReadLockAsync(TimeSpan, CancellationToken)
Tries to enter the lock in read mode asynchronously, with an optional time-out.
Declaration
public Task<bool> TryEnterReadLockAsync(TimeSpan timeout, CancellationToken token)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | timeout | The interval to wait for the lock. |
| CancellationToken | token | The token that can be used to abort lock acquisition. |
Returns
| Type | Description |
|---|---|
| Task<Boolean> | true if the caller entered read mode; otherwise, false. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Time-out value is negative. |
| ObjectDisposedException | This object has been disposed. |
TryEnterUpgradeableReadLock()
Attempts to obtain upgradeable reader lock synchronously without blocking caller thread.
Declaration
public bool TryEnterUpgradeableReadLock()
Returns
| Type | Description |
|---|---|
| Boolean | true if lock is taken successfuly; otherwise, false. |
Exceptions
| Type | Condition |
|---|---|
| ObjectDisposedException | This object has been disposed. |
TryEnterUpgradeableReadLockAsync(TimeSpan)
Tries to enter the lock in upgradeable mode asynchronously, with an optional time-out.
Declaration
public Task<bool> TryEnterUpgradeableReadLockAsync(TimeSpan timeout)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | timeout | The interval to wait for the lock. |
Returns
| Type | Description |
|---|---|
| Task<Boolean> | true if the caller entered upgradeable mode; otherwise, false. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Time-out value is negative. |
| ObjectDisposedException | This object has been disposed. |
TryEnterUpgradeableReadLockAsync(TimeSpan, CancellationToken)
Tries to enter the lock in upgradeable mode asynchronously, with an optional time-out.
Declaration
public Task<bool> TryEnterUpgradeableReadLockAsync(TimeSpan timeout, CancellationToken token)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | timeout | The interval to wait for the lock. |
| CancellationToken | token | The token that can be used to abort lock acquisition. |
Returns
| Type | Description |
|---|---|
| Task<Boolean> | true if the caller entered upgradeable mode; otherwise, false. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Time-out value is negative. |
| ObjectDisposedException | This object has been disposed. |
TryEnterWriteLock()
Attempts to obtain writer lock synchronously without blocking caller thread.
Declaration
public bool TryEnterWriteLock()
Returns
| Type | Description |
|---|---|
| Boolean | true if lock is taken successfuly; otherwise, false. |
Exceptions
| Type | Condition |
|---|---|
| ObjectDisposedException | This object has been disposed. |
TryEnterWriteLock(AsyncReaderWriterLock.LockStamp)
Attempts to acquire write lock without blocking.
Declaration
public bool TryEnterWriteLock(in AsyncReaderWriterLock.LockStamp stamp)
Parameters
| Type | Name | Description |
|---|---|---|
| AsyncReaderWriterLock.LockStamp | stamp | The stamp of the read lock. |
Returns
| Type | Description |
|---|---|
| Boolean | true if lock is acquired successfully; otherwise, false. |
Exceptions
| Type | Condition |
|---|---|
| ObjectDisposedException | This object has been disposed. |
TryEnterWriteLockAsync(TimeSpan)
Tries to enter the lock in write mode asynchronously, with an optional time-out.
Declaration
public Task<bool> TryEnterWriteLockAsync(TimeSpan timeout)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | timeout | The interval to wait for the lock. |
Returns
| Type | Description |
|---|---|
| Task<Boolean> | true if the caller entered write mode; otherwise, false. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Time-out value is negative. |
| ObjectDisposedException | This object has been disposed. |
TryEnterWriteLockAsync(TimeSpan, CancellationToken)
Tries to enter the lock in write mode asynchronously, with an optional time-out.
Declaration
public Task<bool> TryEnterWriteLockAsync(TimeSpan timeout, CancellationToken token)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | timeout | The interval to wait for the lock. |
| CancellationToken | token | The token that can be used to abort lock acquisition. |
Returns
| Type | Description |
|---|---|
| Task<Boolean> | true if the caller entered write mode; otherwise, false. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Time-out value is negative. |
| ObjectDisposedException | This object has been disposed. |
TryOptimisticRead()
Returns a stamp that can be validated later.
Declaration
public AsyncReaderWriterLock.LockStamp TryOptimisticRead()
Returns
| Type | Description |
|---|---|
| AsyncReaderWriterLock.LockStamp | Optimistic read stamp. May be invalid. |
Exceptions
| Type | Condition |
|---|---|
| ObjectDisposedException | This object has been disposed. |