/// <summary>
 /// Acquires reader lock associated with the given object.
 /// </summary>
 /// <typeparam name="T">The type of the object to be locked.</typeparam>
 /// <param name="obj">The object to be locked.</param>
 /// <param name="timeout">The interval to wait for the lock.</param>
 /// <returns>The acquired lock holder.</returns>
 /// <exception cref="TimeoutException">The lock cannot be acquired during the specified amount of time.</exception>
 public static Task <AsyncLock.Holder> AcquireReadLockAsync <T>(this T obj, TimeSpan timeout) where T : class =>
 AsyncLock.ReadLock(obj.GetReaderWriterLock(), false).Acquire(timeout);
Beispiel #2
0
 /// <summary>
 /// Acquires reader lock associated with the given object.
 /// </summary>
 /// <typeparam name="T">The type of the object to be locked.</typeparam>
 /// <param name="obj">The object to be locked.</param>
 /// <param name="token">The token that can be used to abort acquisition operation.</param>
 /// <returns>The acquired lock holder.</returns>
 public static Task <AsyncLock.Holder> AcquireWriteLockAsync <T>(this T obj, CancellationToken token)
     where T : class => AsyncLock.WriteLock(obj.GetReaderWriterLock()).AcquireAsync(token);
Beispiel #3
0
 /// <summary>
 /// Acquires upgradeable lock associated with the given object.
 /// </summary>
 /// <typeparam name="T">The type of the object to be locked.</typeparam>
 /// <param name="obj">The object to be locked.</param>
 /// <param name="token">The token that can be used to abort acquisition operation.</param>
 /// <returns>The acquired lock holder.</returns>
 public static Task <AsyncLock.Holder> AcquireUpgradeableReadLockAsync <T>(this T obj, CancellationToken token)
     where T : class => AsyncLock.ReadLock(obj.GetReaderWriterLock(), true).AcquireAsync(token);
Beispiel #4
0
 /// <summary>
 /// Acquires writer lock associated with the given object.
 /// </summary>
 /// <typeparam name="T">The type of the object to be locked.</typeparam>
 /// <param name="obj">The object to be locked.</param>
 /// <param name="timeout">The interval to wait for the lock.</param>
 /// <returns>The acquired lock holder.</returns>
 /// <exception cref="TimeoutException">The lock cannot be acquired during the specified amount of time.</exception>
 public static Task <AsyncLock.Holder> AcquireWriteLockAsync <T>(this T obj, TimeSpan timeout)
     where T : class => AsyncLock.WriteLock(obj.GetReaderWriterLock()).AcquireAsync(timeout);