You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add '[EditorBrowsable(Never)]' to APIs
* Add 'GetOrAdd' API
* Add 'GetOrAdd' API
* Add 'GetOrAdd' API
* Update ref assembly
* Add unit tests
* Add XML docs for new APIs
* Remove 'Atomically' to clarify docs
* Convert uses to new APIs
* Remove leftover unused method
* Switch 'GetOrCreateComInterfaceForObject' to local type
* Apply suggestions from code review
* Lower threshold time for new tests
---------
Co-authored-by: Jan Kotas <[email protected]>
Copy file name to clipboardExpand all lines: src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/Dispensers/DispenserThatReusesAsLongAsKeyIsAlive.cs
+1-8Lines changed: 1 addition & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -14,23 +14,16 @@ internal sealed class DispenserThatReusesAsLongAsKeyIsAlive<K, [DynamicallyAcces
Copy file name to clipboardExpand all lines: src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.NativeAot.cs
/// Atomically searches for a specified key in the table and returns the corresponding value.
192
-
/// If the key does not exist in the table, the method invokes a callback method to create a
193
-
/// value that is bound to the specified key.
192
+
/// Searches for a specified key in the table and returns the corresponding value. If the key does
193
+
/// not exist in the table, the method adds the given value and binds it to the specified key.
194
+
/// </summary>
195
+
/// <param name="key">The key of the value to find. It cannot be <see langword="null"/>.</param>
196
+
/// <param name="value">The value to add and bind to <typeparamref name="TKey"/>, if one does not exist already.</param>
197
+
/// <returns>The value bound to <typeparamref name="TKey"/> in the current <see cref="ConditionalWeakTable{TKey, TValue}"/> instance, after the method completes.</returns>
198
+
/// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception>
199
+
publicTValueGetOrAdd(TKeykey,TValuevalue)
200
+
{
201
+
// key is validated by TryGetValue
202
+
if(TryGetValue(key,outTValue?existingValue))
203
+
{
204
+
returnexistingValue;
205
+
}
206
+
207
+
returnGetOrAddLocked(key,value);
208
+
}
209
+
210
+
/// <summary>
211
+
/// Searches for a specified key in the table and returns the corresponding value. If the key does not exist
212
+
/// in the table, the method invokes the supplied factory to create a value that is bound to the specified key.
213
+
/// </summary>
214
+
/// <param name="key">The key of the value to find. It cannot be <see langword="null"/>.</param>
215
+
/// <param name="valueFactory">The callback that creates a value for key, if one does not exist already. It cannot be <see langword="null"/>.</param>
216
+
/// <returns>The value bound to <typeparamref name="TKey"/> in the current <see cref="ConditionalWeakTable{TKey, TValue}"/> instance, after the method completes.</returns>
217
+
/// <exception cref="ArgumentNullException"><paramref name="key"/> or <paramref name="valueFactory"/> are <see langword="null"/>.</exception>
218
+
/// <remarks>
219
+
/// If multiple threads try to initialize the same key, the table may invoke <paramref name="valueFactory"/> multiple times
220
+
/// with the same key. Exactly one of these calls will succeed and the returned value of that call will be the one added to
221
+
/// the table and returned by all the racing <see cref="GetOrAdd(TKey, Func{TKey, TValue})"/> calls. This rule permits the
222
+
/// table to invoke <paramref name="valueFactory"/> outside the internal table lock, to prevent deadlocks.
/// Searches for a specified key in the table and returns the corresponding value. If the key does not exist
242
+
/// in the table, the method invokes the supplied factory to create a value that is bound to the specified key.
243
+
/// </summary>
244
+
/// <typeparam name="TArg">The type of the additional argument to use with the value factory.</typeparam>
245
+
/// <param name="key">The key of the value to find. It cannot be <see langword="null"/>.</param>
246
+
/// <param name="valueFactory">The callback that creates a value for key, if one does not exist already. It cannot be <see langword="null"/>.</param>
247
+
/// <param name="factoryArgument">The additional argument to supply to <paramref name="valueFactory"/> upon invocation.</param>
248
+
/// <returns>The value bound to <typeparamref name="TKey"/> in the current <see cref="ConditionalWeakTable{TKey, TValue}"/> instance, after the method completes.</returns>
249
+
/// <exception cref="ArgumentNullException"><paramref name="key"/> or <paramref name="valueFactory"/> are <see langword="null"/>.</exception>
250
+
/// <remarks>
251
+
/// If multiple threads try to initialize the same key, the table may invoke <paramref name="valueFactory"/> multiple times with the
252
+
/// same key. Exactly one of these calls will succeed and the returned value of that call will be the one added to the table and
253
+
/// returned by all the racing <see cref="GetOrAdd{TArg}(TKey, Func{TKey, TArg, TValue}, TArg)"/> calls. This rule permits the
254
+
/// table to invoke <paramref name="valueFactory"/> outside the internal table lock, to prevent deadlocks.
0 commit comments