Class AsyncKeyReaderWriterLock<TKey>
- Namespace
- SixLabors.ImageSharp.Web.Synchronization
- Assembly
- SixLabors.ImageSharp.Web.dll
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.
public class AsyncKeyReaderWriterLock<TKey> where TKey : notnull
Type Parameters
TKeyThe type of the key.
- Inheritance
-
AsyncKeyReaderWriterLock<TKey>
- Inherited Members
Constructors
AsyncKeyReaderWriterLock(int)
Initializes a new instance of the AsyncKeyReaderWriterLock<TKey> class.
public AsyncKeyReaderWriterLock(int maxPoolSize = 64)
Parameters
maxPoolSizeintThe maximum number of locks that should be pooled for reuse.
Methods
ReaderLockAsync(TKey)
Locks the current thread in read mode asynchronously.
public Task<IDisposable> ReaderLockAsync(TKey key)
Parameters
keyTKeyThe key identifying the specific object to lock against.
Returns
- Task<IDisposable>
The IDisposable that will release the lock.
WriterLockAsync(TKey)
Locks the current thread in write mode asynchronously.
public Task<IDisposable> WriterLockAsync(TKey key)
Parameters
keyTKeyThe key identifying the specific object to lock against.
Returns
- Task<IDisposable>
The IDisposable that will release the lock.