Table of Contents

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

TKey

The 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

maxPoolSize int

The 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

key TKey

The 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

key TKey

The key identifying the specific object to lock against.

Returns

Task<IDisposable>

The IDisposable that will release the lock.