Class AsyncKeyReaderWriterLock<TKey>
Extension of the AsyncReaderWriterLock that enables fine-grained locking on a given key. Concurrent write lock requests using different keys can execute simultaneously, while requests to lock using the same key will be forced to wait. This object is thread-safe and internally uses a pooling mechanism to minimize allocation of new locks.
Inherited Members
Namespace: SixLabors.ImageSharp.Web.Synchronization
Assembly: SixLabors.ImageSharp.Web.dll
Syntax
public class AsyncKeyReaderWriterLock<TKey> where TKey : notnull
Type Parameters
Name | Description |
---|---|
TKey | The type of the key. |
Constructors
| Edit this page View SourceAsyncKeyReaderWriterLock(int)
Initializes a new instance of the AsyncKeyReaderWriterLock<TKey> class.
Declaration
public AsyncKeyReaderWriterLock(int maxPoolSize = 64)
Parameters
Type | Name | Description |
---|---|---|
int | maxPoolSize | The maximum number of locks that should be pooled for reuse. |
Methods
| Edit this page View SourceReaderLockAsync(TKey)
Locks the current thread in read mode asynchronously.
Declaration
public Task<IDisposable> ReaderLockAsync(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key identifying the specific object to lock against. |
Returns
Type | Description |
---|---|
Task<IDisposable> | The IDisposable that will release the lock. |
WriterLockAsync(TKey)
Locks the current thread in write mode asynchronously.
Declaration
public Task<IDisposable> WriterLockAsync(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key identifying the specific object to lock against. |
Returns
Type | Description |
---|---|
Task<IDisposable> | The IDisposable that will release the lock. |