Class AsyncReaderWriterLock
Represents asynchronous version of
Implements
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public class AsyncReaderWriterLock : QueuedSynchronizer, ISynchronizer
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 SourceEnterReadLock(CancellationToken)
Enters the lock in read mode asynchronously.
Declaration
public Task EnterReadLock(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. |
EnterReadLock(TimeSpan)
Enters the lock in read mode asynchronously.
Declaration
public Task EnterReadLock(TimeSpan timeout)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | timeout | The interval to wait for the lock. |
Returns
Type | Description |
---|---|
Task | The task representing acquisition operation. |
EnterUpgradeableReadLock(CancellationToken)
Enters the lock in upgradeable mode asynchronously.
Declaration
public Task EnterUpgradeableReadLock(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. |
EnterUpgradeableReadLock(TimeSpan)
Enters the lock in upgradeable mode asynchronously.
Declaration
public Task EnterUpgradeableReadLock(TimeSpan timeout)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | timeout | The interval to wait for the lock. |
Returns
Type | Description |
---|---|
Task | The task representing lock acquisition operation. |
EnterWriteLock(CancellationToken)
Enters the lock in write mode asynchronously.
Declaration
public Task EnterWriteLock(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. |
EnterWriteLock(TimeSpan)
Enters the lock in write mode asynchronously.
Declaration
public Task EnterWriteLock(TimeSpan timeout)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | timeout | The interval to wait for the lock. |
Returns
Type | Description |
---|---|
Task | The task representing lock acquisition operation. |
ExitReadLock()
Exits read mode.
Declaration
public void ExitReadLock()
Remarks
Exiting from the lock is synchronous non-blocking operation. Lock acquisition is an asynchronous operation.
ExitUpgradeableReadLock()
Exits upgradeable mode.
Declaration
public void ExitUpgradeableReadLock()
Remarks
Exiting from the lock is synchronous non-blocking operation. Lock acquisition is an asynchronous operation.
ExitWriteLock()
Exits write mode.
Declaration
public void ExitWriteLock()
Remarks
Exiting from the lock is synchronous non-blocking operation. Lock acquisition is an asynchronous operation.
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. |
TryEnterReadLock(TimeSpan)
Tries to enter the lock in read mode asynchronously, with an optional time-out.
Declaration
public Task<bool> TryEnterReadLock(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. |
TryEnterReadLock(TimeSpan, CancellationToken)
Tries to enter the lock in read mode asynchronously, with an optional time-out.
Declaration
public Task<bool> TryEnterReadLock(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. |
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. |
TryEnterUpgradeableReadLock(TimeSpan)
Tries to enter the lock in upgradeable mode asynchronously, with an optional time-out.
Declaration
public Task<bool> TryEnterUpgradeableReadLock(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. |
TryEnterUpgradeableReadLock(TimeSpan, CancellationToken)
Tries to enter the lock in upgradeable mode asynchronously, with an optional time-out.
Declaration
public Task<bool> TryEnterUpgradeableReadLock(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. |
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. |
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. |
TryEnterWriteLock(TimeSpan)
Tries to enter the lock in write mode asynchronously, with an optional time-out.
Declaration
public Task<bool> TryEnterWriteLock(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. |
TryEnterWriteLock(TimeSpan, CancellationToken)
Tries to enter the lock in write mode asynchronously, with an optional time-out.
Declaration
public Task<bool> TryEnterWriteLock(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. |
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. |