@@ -154,7 +154,7 @@ private static AsyncLock GetExclusiveLock<T>(this T obj)
154
154
/// <returns>The acquired lock holder.</returns>
155
155
/// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
156
156
public static ValueTask < AsyncLock . Holder > AcquireWriteLockAsync < T > ( this T obj , CancellationToken token = default )
157
- where T : class => AsyncLock . WriteLock ( obj . GetReaderWriterLock ( ) ) . AcquireAsync ( token ) ;
157
+ where T : class => AcquireWriteLockAsync ( obj , upgrade : false , token ) ;
158
158
159
159
/// <summary>
160
160
/// Acquires reader lock associated with the given object.
@@ -164,7 +164,40 @@ private static AsyncLock GetExclusiveLock<T>(this T obj)
164
164
/// <param name="timeout">The interval to wait for the lock.</param>
165
165
/// <param name="token">The token that can be used to abort acquisition operation.</param>
166
166
/// <returns>The acquired lock holder.</returns>
167
+ /// <exception cref="TimeoutException">The lock cannot be acquired during the specified amount of time.</exception>
167
168
/// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
168
169
public static ValueTask < AsyncLock . Holder > AcquireWriteLockAsync < T > ( this T obj , TimeSpan timeout , CancellationToken token = default )
169
- where T : class => AsyncLock . WriteLock ( obj . GetReaderWriterLock ( ) ) . AcquireAsync ( timeout , token ) ;
170
+ where T : class => AcquireWriteLockAsync ( obj , upgrade : false , timeout , token ) ;
171
+
172
+ /// <summary>
173
+ /// Acquires reader lock associated with the given object.
174
+ /// </summary>
175
+ /// <typeparam name="T">The type of the object to be locked.</typeparam>
176
+ /// <param name="obj">The object to be locked.</param>
177
+ /// <param name="upgrade">
178
+ /// <see langword="true"/> to upgrade from read lock;
179
+ /// otherwise, <see langword="false"/>.
180
+ /// </param>
181
+ /// <param name="token">The token that can be used to abort acquisition operation.</param>
182
+ /// <returns>The acquired lock holder.</returns>
183
+ /// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
184
+ public static ValueTask < AsyncLock . Holder > AcquireWriteLockAsync < T > ( this T obj , bool upgrade , CancellationToken token = default )
185
+ where T : class => AsyncLock . WriteLock ( obj . GetReaderWriterLock ( ) , upgrade ) . AcquireAsync ( token ) ;
186
+
187
+ /// <summary>
188
+ /// Acquires reader lock associated with the given object.
189
+ /// </summary>
190
+ /// <typeparam name="T">The type of the object to be locked.</typeparam>
191
+ /// <param name="obj">The object to be locked.</param>
192
+ /// <param name="upgrade">
193
+ /// <see langword="true"/> to upgrade from read lock;
194
+ /// otherwise, <see langword="false"/>.
195
+ /// </param>
196
+ /// <param name="timeout">The interval to wait for the lock.</param>
197
+ /// <param name="token">The token that can be used to abort acquisition operation.</param>
198
+ /// <returns>The acquired lock holder.</returns>
199
+ /// <exception cref="TimeoutException">The lock cannot be acquired during the specified amount of time.</exception>
200
+ /// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
201
+ public static ValueTask < AsyncLock . Holder > AcquireWriteLockAsync < T > ( this T obj , bool upgrade , TimeSpan timeout , CancellationToken token = default )
202
+ where T : class => AsyncLock . WriteLock ( obj . GetReaderWriterLock ( ) , upgrade ) . AcquireAsync ( timeout , token ) ;
170
203
}
0 commit comments