@@ -69,8 +69,9 @@ private static AsyncLock GetExclusiveLock<T>(this T obj)
69
69
/// <param name="timeout">The interval to wait for the lock.</param>
70
70
/// <returns>The acquired lock holder.</returns>
71
71
/// <exception cref="TimeoutException">The lock cannot be acquired during the specified amount of time.</exception>
72
- public static ValueTask < AsyncLock . Holder > AcquireLockAsync < T > ( this T obj , TimeSpan timeout )
73
- where T : class => obj . GetExclusiveLock ( ) . AcquireAsync ( timeout ) ;
72
+ [ Obsolete ( "Use AcquireLockAsync(T, TimeSpan, CancellationToken) overload instead." , error : true ) ]
73
+ public static ValueTask < AsyncLock . Holder > AcquireLockAsync < T > ( T obj , TimeSpan timeout )
74
+ where T : class => AcquireLockAsync ( obj , timeout , CancellationToken . None ) ;
74
75
75
76
/// <summary>
76
77
/// Acquires exclusive lock associated with the given object.
@@ -79,9 +80,23 @@ private static AsyncLock GetExclusiveLock<T>(this T obj)
79
80
/// <param name="obj">The object to be locked.</param>
80
81
/// <param name="token">The token that can be used to abort acquisition operation.</param>
81
82
/// <returns>The acquired lock holder.</returns>
82
- public static ValueTask < AsyncLock . Holder > AcquireLockAsync < T > ( this T obj , CancellationToken token )
83
+ /// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
84
+ public static ValueTask < AsyncLock . Holder > AcquireLockAsync < T > ( this T obj , CancellationToken token = default )
83
85
where T : class => obj . GetExclusiveLock ( ) . AcquireAsync ( token ) ;
84
86
87
+ /// <summary>
88
+ /// Acquires exclusive lock associated with the given object.
89
+ /// </summary>
90
+ /// <typeparam name="T">The type of the object to be locked.</typeparam>
91
+ /// <param name="obj">The object to be locked.</param>
92
+ /// <param name="timeout">The interval to wait for the lock.</param>
93
+ /// <param name="token">The token that can be used to abort acquisition operation.</param>
94
+ /// <returns>The acquired lock holder.</returns>
95
+ /// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
96
+ /// <exception cref="TimeoutException">The lock cannot be acquired during the specified amount of time.</exception>
97
+ public static ValueTask < AsyncLock . Holder > AcquireLockAsync < T > ( this T obj , TimeSpan timeout , CancellationToken token = default )
98
+ where T : class => obj . GetExclusiveLock ( ) . AcquireAsync ( timeout , token ) ;
99
+
85
100
/// <summary>
86
101
/// Acquires reader lock associated with the given object.
87
102
/// </summary>
@@ -90,8 +105,9 @@ private static AsyncLock GetExclusiveLock<T>(this T obj)
90
105
/// <param name="timeout">The interval to wait for the lock.</param>
91
106
/// <returns>The acquired lock holder.</returns>
92
107
/// <exception cref="TimeoutException">The lock cannot be acquired during the specified amount of time.</exception>
93
- public static ValueTask < AsyncLock . Holder > AcquireReadLockAsync < T > ( this T obj , TimeSpan timeout )
94
- where T : class => AsyncLock . ReadLock ( obj . GetReaderWriterLock ( ) ) . AcquireAsync ( timeout ) ;
108
+ [ Obsolete ( "Use AcquireReadLockAsync(T, TimeSpan, CancellationToken) overload instead." , error : true ) ]
109
+ public static ValueTask < AsyncLock . Holder > AcquireReadLockAsync < T > ( T obj , TimeSpan timeout )
110
+ where T : class => AcquireReadLockAsync ( obj , timeout , CancellationToken . None ) ;
95
111
96
112
/// <summary>
97
113
/// Acquires reader lock associated with the given object.
@@ -100,9 +116,23 @@ private static AsyncLock GetExclusiveLock<T>(this T obj)
100
116
/// <param name="obj">The object to be locked.</param>
101
117
/// <param name="token">The token that can be used to abort acquisition operation.</param>
102
118
/// <returns>The acquired lock holder.</returns>
103
- public static ValueTask < AsyncLock . Holder > AcquireReadLockAsync < T > ( this T obj , CancellationToken token )
119
+ /// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
120
+ public static ValueTask < AsyncLock . Holder > AcquireReadLockAsync < T > ( this T obj , CancellationToken token = default )
104
121
where T : class => AsyncLock . ReadLock ( obj . GetReaderWriterLock ( ) ) . AcquireAsync ( token ) ;
105
122
123
+ /// <summary>
124
+ /// Acquires reader lock associated with the given object.
125
+ /// </summary>
126
+ /// <typeparam name="T">The type of the object to be locked.</typeparam>
127
+ /// <param name="obj">The object to be locked.</param>
128
+ /// <param name="timeout">The interval to wait for the lock.</param>
129
+ /// <param name="token">The token that can be used to abort acquisition operation.</param>
130
+ /// <returns>The acquired lock holder.</returns>
131
+ /// <exception cref="TimeoutException">The lock cannot be acquired during the specified amount of time.</exception>
132
+ /// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
133
+ public static ValueTask < AsyncLock . Holder > AcquireReadLockAsync < T > ( this T obj , TimeSpan timeout , CancellationToken token = default )
134
+ where T : class => AsyncLock . ReadLock ( obj . GetReaderWriterLock ( ) ) . AcquireAsync ( timeout , token ) ;
135
+
106
136
/// <summary>
107
137
/// Acquires writer lock associated with the given object.
108
138
/// </summary>
@@ -111,8 +141,9 @@ private static AsyncLock GetExclusiveLock<T>(this T obj)
111
141
/// <param name="timeout">The interval to wait for the lock.</param>
112
142
/// <returns>The acquired lock holder.</returns>
113
143
/// <exception cref="TimeoutException">The lock cannot be acquired during the specified amount of time.</exception>
114
- public static ValueTask < AsyncLock . Holder > AcquireWriteLockAsync < T > ( this T obj , TimeSpan timeout )
115
- where T : class => AsyncLock . WriteLock ( obj . GetReaderWriterLock ( ) ) . AcquireAsync ( timeout ) ;
144
+ [ Obsolete ( "Use AcquireWriteLockAsync(T, TimeSpan, CancellationToken) overload instead." , error : true ) ]
145
+ public static ValueTask < AsyncLock . Holder > AcquireWriteLockAsync < T > ( T obj , TimeSpan timeout )
146
+ where T : class => AcquireWriteLockAsync ( obj , timeout , CancellationToken . None ) ;
116
147
117
148
/// <summary>
118
149
/// Acquires reader lock associated with the given object.
@@ -121,6 +152,19 @@ private static AsyncLock GetExclusiveLock<T>(this T obj)
121
152
/// <param name="obj">The object to be locked.</param>
122
153
/// <param name="token">The token that can be used to abort acquisition operation.</param>
123
154
/// <returns>The acquired lock holder.</returns>
124
- public static ValueTask < AsyncLock . Holder > AcquireWriteLockAsync < T > ( this T obj , CancellationToken token )
155
+ /// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
156
+ public static ValueTask < AsyncLock . Holder > AcquireWriteLockAsync < T > ( this T obj , CancellationToken token = default )
125
157
where T : class => AsyncLock . WriteLock ( obj . GetReaderWriterLock ( ) ) . AcquireAsync ( token ) ;
158
+
159
+ /// <summary>
160
+ /// Acquires reader lock associated with the given object.
161
+ /// </summary>
162
+ /// <typeparam name="T">The type of the object to be locked.</typeparam>
163
+ /// <param name="obj">The object to be locked.</param>
164
+ /// <param name="timeout">The interval to wait for the lock.</param>
165
+ /// <param name="token">The token that can be used to abort acquisition operation.</param>
166
+ /// <returns>The acquired lock holder.</returns>
167
+ /// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
168
+ 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 ) ;
126
170
}
0 commit comments