summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/Collections/Concurrent
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2016-12-27 16:46:08 +0900
committerJiyoung Yun <jy910.yun@samsung.com>2016-12-27 16:46:08 +0900
commitdb20f3f1bb8595633a7e16c8900fd401a453a6b5 (patch)
treee5435159cd1bf0519276363a6fe1663d1721bed3 /src/mscorlib/src/System/Collections/Concurrent
parent4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (diff)
downloadcoreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.tar.gz
coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.tar.bz2
coreclr-db20f3f1bb8595633a7e16c8900fd401a453a6b5.zip
Imported Upstream version 1.0.0.9127upstream/1.0.0.9127
Diffstat (limited to 'src/mscorlib/src/System/Collections/Concurrent')
-rw-r--r--src/mscorlib/src/System/Collections/Concurrent/ConcurrentDictionary.cs216
-rw-r--r--src/mscorlib/src/System/Collections/Concurrent/ConcurrentQueue.cs21
-rw-r--r--src/mscorlib/src/System/Collections/Concurrent/ConcurrentStack.cs91
-rw-r--r--src/mscorlib/src/System/Collections/Concurrent/IProducerConsumerCollection.cs2
-rw-r--r--src/mscorlib/src/System/Collections/Concurrent/OrderablePartitioner.cs1
-rw-r--r--src/mscorlib/src/System/Collections/Concurrent/Partitioner.cs1
-rw-r--r--src/mscorlib/src/System/Collections/Concurrent/PartitionerStatic.cs104
7 files changed, 109 insertions, 327 deletions
diff --git a/src/mscorlib/src/System/Collections/Concurrent/ConcurrentDictionary.cs b/src/mscorlib/src/System/Collections/Concurrent/ConcurrentDictionary.cs
index d805dc8be7..c1a6f7564c 100644
--- a/src/mscorlib/src/System/Collections/Concurrent/ConcurrentDictionary.cs
+++ b/src/mscorlib/src/System/Collections/Concurrent/ConcurrentDictionary.cs
@@ -28,7 +28,6 @@ using System.Security.Permissions;
namespace System.Collections.Concurrent
{
-
/// <summary>
/// Represents a thread-safe collection of keys and values.
/// </summary>
@@ -38,13 +37,9 @@ namespace System.Collections.Concurrent
/// All public and protected members of <see cref="ConcurrentDictionary{TKey,TValue}"/> are thread-safe and may be used
/// concurrently from multiple threads.
/// </remarks>
-#if !FEATURE_CORECLR
- [Serializable]
-#endif
[ComVisible(false)]
[DebuggerTypeProxy(typeof(Mscorlib_DictionaryDebugView<,>))]
[DebuggerDisplay("Count = {Count}")]
- [HostProtection(Synchronization = true, ExternalThreading = true)]
public class ConcurrentDictionary<TKey, TValue> : IDictionary<TKey, TValue>, IDictionary, IReadOnlyDictionary<TKey, TValue>
{
/// <summary>
@@ -68,41 +63,20 @@ namespace System.Collections.Concurrent
m_comparer = comparer;
}
}
-#if !FEATURE_CORECLR
- [NonSerialized]
-#endif
+
private volatile Tables m_tables; // Internal tables of the dictionary
// NOTE: this is only used for compat reasons to serialize the comparer.
// This should not be accessed from anywhere else outside of the serialization methods.
internal IEqualityComparer<TKey> m_comparer;
-#if !FEATURE_CORECLR
- [NonSerialized]
-#endif
private readonly bool m_growLockArray; // Whether to dynamically increase the size of the striped lock
// How many times we resized becaused of collisions.
// This is used to make sure we don't resize the dictionary because of multi-threaded Add() calls
// that generate collisions. Whenever a GrowTable() should be the only place that changes this
-#if !FEATURE_CORECLR
- // The field should be have been marked as NonSerialized but because we shipped it without that attribute in 4.5.1.
- // we can't add it back without breaking compat. To maximize compat we are going to keep the OptionalField attribute
- // This will prevent cases where the field was not serialized.
- [OptionalField]
-#endif
private int m_keyRehashCount;
-#if !FEATURE_CORECLR
- [NonSerialized]
-#endif
private int m_budget; // The maximum number of elements per lock before a resize operation is triggered
-#if !FEATURE_CORECLR // These fields are not used in CoreCLR
- private KeyValuePair<TKey, TValue>[] m_serializationArray; // Used for custom serialization
-
- private int m_serializationConcurrencyLevel; // used to save the concurrency level in serialization
-
- private int m_serializationCapacity; // used to save the capacity in serialization
-#endif
// The default concurrency level is DEFAULT_CONCURRENCY_MULTIPLIER * #CPUs. The higher the
// DEFAULT_CONCURRENCY_MULTIPLIER, the more concurrent writes can take place without interference
// and blocking, but also the more expensive operations that require all locks become (e.g. table
@@ -229,7 +203,7 @@ namespace System.Collections.Concurrent
public ConcurrentDictionary(IEnumerable<KeyValuePair<TKey, TValue>> collection, IEqualityComparer<TKey> comparer)
: this(comparer)
{
- if (collection == null) throw new ArgumentNullException("collection");
+ if (collection == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection);
InitializeFromCollection(collection);
}
@@ -259,8 +233,8 @@ namespace System.Collections.Concurrent
int concurrencyLevel, IEnumerable<KeyValuePair<TKey, TValue>> collection, IEqualityComparer<TKey> comparer)
: this(concurrencyLevel, DEFAULT_CAPACITY, false, comparer)
{
- if (collection == null) throw new ArgumentNullException("collection");
- if (comparer == null) throw new ArgumentNullException("comparer");
+ if (collection == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection);
+ if (comparer == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparer);
InitializeFromCollection(collection);
}
@@ -270,11 +244,11 @@ namespace System.Collections.Concurrent
TValue dummy;
foreach (KeyValuePair<TKey, TValue> pair in collection)
{
- if (pair.Key == null) throw new ArgumentNullException("key");
+ if (pair.Key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
if (!TryAddInternal(pair.Key, pair.Value, false, false, out dummy))
{
- throw new ArgumentException(GetResource("ConcurrentDictionary_SourceContainsDuplicateKeys"));
+ ThrowHelper.ThrowArgumentException(ExceptionResource.ConcurrentDictionary_SourceContainsDuplicateKeys);
}
}
@@ -312,13 +286,13 @@ namespace System.Collections.Concurrent
{
if (concurrencyLevel < 1)
{
- throw new ArgumentOutOfRangeException("concurrencyLevel", GetResource("ConcurrentDictionary_ConcurrencyLevelMustBePositive"));
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.concurrencyLevel, ExceptionResource.ConcurrentDictionary_ConcurrencyLevelMustBePositive);
}
if (capacity < 0)
{
- throw new ArgumentOutOfRangeException("capacity", GetResource("ConcurrentDictionary_CapacityMustNotBeNegative"));
+ ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.capacity, ExceptionResource.ConcurrentDictionary_CapacityMustNotBeNegative);
}
- if (comparer == null) throw new ArgumentNullException("comparer");
+ if (comparer == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparer);
// The capacity should be at least as large as the concurrency level. Otherwise, we would have locks that don't guard
// any buckets.
@@ -358,7 +332,7 @@ namespace System.Collections.Concurrent
/// contains too many elements.</exception>
public bool TryAdd(TKey key, TValue value)
{
- if (key == null) throw new ArgumentNullException("key");
+ if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
TValue dummy;
return TryAddInternal(key, value, false, true, out dummy);
}
@@ -375,7 +349,7 @@ namespace System.Collections.Concurrent
/// (Nothing in Visual Basic).</exception>
public bool ContainsKey(TKey key)
{
- if (key == null) throw new ArgumentNullException("key");
+ if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
TValue throwAwayValue;
return TryGetValue(key, out throwAwayValue);
@@ -395,7 +369,7 @@ namespace System.Collections.Concurrent
/// (Nothing in Visual Basic).</exception>
public bool TryRemove(TKey key, out TValue value)
{
- if (key == null) throw new ArgumentNullException("key");
+ if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
return TryRemoveInternal(key, out value, false, default(TValue));
}
@@ -486,7 +460,7 @@ namespace System.Collections.Concurrent
[SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "Reviewed for thread safety")]
public bool TryGetValue(TKey key, out TValue value)
{
- if (key == null) throw new ArgumentNullException("key");
+ if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
int bucketNo, lockNoUnused;
@@ -531,7 +505,7 @@ namespace System.Collections.Concurrent
[SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "Reviewed for thread safety")]
public bool TryUpdate(TKey key, TValue newValue, TValue comparisonValue)
{
- if (key == null) throw new ArgumentNullException("key");
+ if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
IEqualityComparer<TValue> valueComparer = EqualityComparer<TValue>.Default;
@@ -642,8 +616,8 @@ namespace System.Collections.Concurrent
[SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "ConcurrencyCop just doesn't know about these locks")]
void ICollection<KeyValuePair<TKey, TValue>>.CopyTo(KeyValuePair<TKey, TValue>[] array, int index)
{
- if (array == null) throw new ArgumentNullException("array");
- if (index < 0) throw new ArgumentOutOfRangeException("index", GetResource("ConcurrentDictionary_IndexIsNegative"));
+ if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
+ if (index < 0) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ConcurrentDictionary_IndexIsNegative);
int locksAcquired = 0;
try
@@ -659,7 +633,7 @@ namespace System.Collections.Concurrent
if (array.Length - count < index || count < 0) //"count" itself or "count + index" can overflow
{
- throw new ArgumentException(GetResource("ConcurrentDictionary_ArrayNotLargeEnough"));
+ ThrowHelper.ThrowArgumentException(ExceptionResource.ConcurrentDictionary_ArrayNotLargeEnough);
}
CopyToPairs(array, index);
@@ -803,11 +777,6 @@ namespace System.Collections.Concurrent
bool resizeDesired = false;
bool lockTaken = false;
-#if FEATURE_RANDOMIZED_STRING_HASHING
-#if !FEATURE_CORECLR
- bool resizeDueToCollisions = false;
-#endif // !FEATURE_CORECLR
-#endif
try
{
@@ -821,12 +790,6 @@ namespace System.Collections.Concurrent
continue;
}
-#if FEATURE_RANDOMIZED_STRING_HASHING
-#if !FEATURE_CORECLR
- int collisionCount = 0;
-#endif // !FEATURE_CORECLR
-#endif
-
// Try to find this key in the bucket
Node prev = null;
for (Node node = tables.m_buckets[bucketNo]; node != null; node = node.m_next)
@@ -864,23 +827,7 @@ namespace System.Collections.Concurrent
return false;
}
prev = node;
-
-#if FEATURE_RANDOMIZED_STRING_HASHING
-#if !FEATURE_CORECLR
- collisionCount++;
-#endif // !FEATURE_CORECLR
-#endif
- }
-
-#if FEATURE_RANDOMIZED_STRING_HASHING
-#if !FEATURE_CORECLR
- if(collisionCount > HashHelpers.HashCollisionThreshold && HashHelpers.IsWellKnownEqualityComparer(comparer))
- {
- resizeDesired = true;
- resizeDueToCollisions = true;
}
-#endif // !FEATURE_CORECLR
-#endif
// The key was not found in the bucket. Insert the key-value pair.
Volatile.Write<Node>(ref tables.m_buckets[bucketNo], new Node(key, value, hashcode, tables.m_buckets[bucketNo]));
@@ -916,16 +863,7 @@ namespace System.Collections.Concurrent
if (resizeDesired)
{
#if FEATURE_RANDOMIZED_STRING_HASHING
-#if !FEATURE_CORECLR
- if (resizeDueToCollisions)
- {
- GrowTable(tables, (IEqualityComparer<TKey>)HashHelpers.GetRandomizedEqualityComparer(comparer), true, m_keyRehashCount);
- }
- else
-#endif // !FEATURE_CORECLR
- {
- GrowTable(tables, tables.m_comparer, false, m_keyRehashCount);
- }
+ GrowTable(tables, tables.m_comparer, false, m_keyRehashCount);
#else
GrowTable(tables, tables.m_comparer, false, m_keyRehashCount);
#endif
@@ -956,13 +894,13 @@ namespace System.Collections.Concurrent
TValue value;
if (!TryGetValue(key, out value))
{
- throw new KeyNotFoundException();
+ ThrowHelper.ThrowKeyNotFoundException();
}
return value;
}
set
{
- if (key == null) throw new ArgumentNullException("key");
+ if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
TValue dummy;
TryAddInternal(key, value, true, true, out dummy);
}
@@ -1026,8 +964,8 @@ namespace System.Collections.Concurrent
/// if the key was not in the dictionary.</returns>
public TValue GetOrAdd(TKey key, Func<TKey, TValue> valueFactory)
{
- if (key == null) throw new ArgumentNullException("key");
- if (valueFactory == null) throw new ArgumentNullException("valueFactory");
+ if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
+ if (valueFactory == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.valueFactory);
TValue resultingValue;
if (TryGetValue(key, out resultingValue))
@@ -1052,7 +990,7 @@ namespace System.Collections.Concurrent
/// key is already in the dictionary, or the new value if the key was not in the dictionary.</returns>
public TValue GetOrAdd(TKey key, TValue value)
{
- if (key == null) throw new ArgumentNullException("key");
+ if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
TValue resultingValue;
TryAddInternal(key, value, false, true, out resultingValue);
@@ -1080,9 +1018,9 @@ namespace System.Collections.Concurrent
/// absent) or the result of updateValueFactory (if the key was present).</returns>
public TValue AddOrUpdate(TKey key, Func<TKey, TValue> addValueFactory, Func<TKey, TValue, TValue> updateValueFactory)
{
- if (key == null) throw new ArgumentNullException("key");
- if (addValueFactory == null) throw new ArgumentNullException("addValueFactory");
- if (updateValueFactory == null) throw new ArgumentNullException("updateValueFactory");
+ if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
+ if (addValueFactory == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.addValueFactory);
+ if (updateValueFactory == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.updateValueFactory);
TValue newValue, resultingValue;
while (true)
@@ -1127,8 +1065,8 @@ namespace System.Collections.Concurrent
/// absent) or the result of updateValueFactory (if the key was present).</returns>
public TValue AddOrUpdate(TKey key, TValue addValue, Func<TKey, TValue, TValue> updateValueFactory)
{
- if (key == null) throw new ArgumentNullException("key");
- if (updateValueFactory == null) throw new ArgumentNullException("updateValueFactory");
+ if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
+ if (updateValueFactory == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.updateValueFactory);
TValue newValue, resultingValue;
while (true)
{
@@ -1207,7 +1145,7 @@ namespace System.Collections.Concurrent
{
if (!TryAdd(key, value))
{
- throw new ArgumentException(GetResource("ConcurrentDictionary_KeyAlreadyExisted"));
+ ThrowHelper.ThrowArgumentException(ExceptionResource.ConcurrentDictionary_KeyAlreadyExisted);
}
}
@@ -1340,8 +1278,7 @@ namespace System.Collections.Concurrent
/// name="keyValuePair"/> is a null reference (Nothing in Visual Basic).</exception>
bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> keyValuePair)
{
- if (keyValuePair.Key == null) throw new ArgumentNullException(GetResource("ConcurrentDictionary_ItemKeyIsNull"));
-
+ if (keyValuePair.Key == null) ThrowHelper.ThrowArgumentNullException(ExceptionResource.ConcurrentDictionary_ItemKeyIsNull);
TValue throwAwayValue;
return TryRemoveInternal(keyValuePair.Key, out throwAwayValue, true, keyValuePair.Value);
}
@@ -1387,17 +1324,17 @@ namespace System.Collections.Concurrent
/// </exception>
void IDictionary.Add(object key, object value)
{
- if (key == null) throw new ArgumentNullException("key");
- if (!(key is TKey)) throw new ArgumentException(GetResource("ConcurrentDictionary_TypeOfKeyIncorrect"));
+ if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
+ if (!(key is TKey)) ThrowHelper.ThrowArgumentException(ExceptionResource.ConcurrentDictionary_TypeOfKeyIncorrect);
- TValue typedValue;
+ TValue typedValue = default(TValue);
try
{
typedValue = (TValue)value;
}
catch (InvalidCastException)
{
- throw new ArgumentException(GetResource("ConcurrentDictionary_TypeOfValueIncorrect"));
+ ThrowHelper.ThrowArgumentException(ExceptionResource.ConcurrentDictionary_TypeOfValueIncorrect);
}
((IDictionary<TKey, TValue>)this).Add((TKey)key, typedValue);
@@ -1415,7 +1352,7 @@ namespace System.Collections.Concurrent
/// (Nothing in Visual Basic).</exception>
bool IDictionary.Contains(object key)
{
- if (key == null) throw new ArgumentNullException("key");
+ if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
return (key is TKey) && ((ConcurrentDictionary<TKey, TValue>)this).ContainsKey((TKey)key);
}
@@ -1475,7 +1412,7 @@ namespace System.Collections.Concurrent
/// (Nothing in Visual Basic).</exception>
void IDictionary.Remove(object key)
{
- if (key == null) throw new ArgumentNullException("key");
+ if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
TValue throwAwayValue;
if (key is TKey)
@@ -1517,7 +1454,7 @@ namespace System.Collections.Concurrent
{
get
{
- if (key == null) throw new ArgumentNullException("key");
+ if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
TValue value;
if (key is TKey && this.TryGetValue((TKey)key, out value))
@@ -1529,10 +1466,10 @@ namespace System.Collections.Concurrent
}
set
{
- if (key == null) throw new ArgumentNullException("key");
+ if (key == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
- if (!(key is TKey)) throw new ArgumentException(GetResource("ConcurrentDictionary_TypeOfKeyIncorrect"));
- if (!(value is TValue)) throw new ArgumentException(GetResource("ConcurrentDictionary_TypeOfValueIncorrect"));
+ if (!(key is TKey)) ThrowHelper.ThrowArgumentException(ExceptionResource.ConcurrentDictionary_TypeOfKeyIncorrect);
+ if (!(value is TValue)) ThrowHelper.ThrowArgumentException(ExceptionResource.ConcurrentDictionary_TypeOfValueIncorrect);
((ConcurrentDictionary<TKey, TValue>)this)[(TKey)key] = (TValue)value;
}
@@ -1563,8 +1500,8 @@ namespace System.Collections.Concurrent
[SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "ConcurrencyCop just doesn't know about these locks")]
void ICollection.CopyTo(Array array, int index)
{
- if (array == null) throw new ArgumentNullException("array");
- if (index < 0) throw new ArgumentOutOfRangeException("index", GetResource("ConcurrentDictionary_IndexIsNegative"));
+ if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
+ if (index < 0) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ConcurrentDictionary_IndexIsNegative);
int locksAcquired = 0;
try
@@ -1581,7 +1518,7 @@ namespace System.Collections.Concurrent
if (array.Length - count < index || count < 0) //"count" itself or "count + index" can overflow
{
- throw new ArgumentException(GetResource("ConcurrentDictionary_ArrayNotLargeEnough"));
+ ThrowHelper.ThrowArgumentException(ExceptionResource.ConcurrentDictionary_ArrayNotLargeEnough);
}
// To be consistent with the behavior of ICollection.CopyTo() in Dictionary<TKey,TValue>,
@@ -1611,7 +1548,7 @@ namespace System.Collections.Concurrent
return;
}
- throw new ArgumentException(GetResource("ConcurrentDictionary_ArrayIncorrectType"), "array");
+ ThrowHelper.ThrowArgumentException(ExceptionResource.ConcurrentDictionary_ArrayIncorrectType, ExceptionArgument.array);
}
finally
{
@@ -1641,7 +1578,8 @@ namespace System.Collections.Concurrent
{
get
{
- throw new NotSupportedException(Environment.GetResourceString("ConcurrentCollection_SyncRoot_NotSupported"));
+ ThrowHelper.ThrowNotSupportedException(ExceptionResource.ConcurrentCollection_SyncRoot_NotSupported);
+ return default(object);
}
}
@@ -1850,13 +1788,6 @@ namespace System.Collections.Concurrent
/// </summary>
private void AcquireAllLocks(ref int locksAcquired)
{
-#if !FEATURE_CORECLR
- if (CDSCollectionETWBCLProvider.Log.IsEnabled())
- {
- CDSCollectionETWBCLProvider.Log.ConcurrentDictionary_AcquiringAllLocks(m_tables.m_buckets.Length);
- }
-#endif //!FEATURE_CORECLR
-
// First, acquire lock 0
AcquireLocks(0, 1, ref locksAcquired);
@@ -1973,19 +1904,7 @@ namespace System.Collections.Concurrent
[Conditional("DEBUG")]
private void Assert(bool condition)
{
- Contract.Assert(condition);
- }
-
- /// <summary>
- /// A helper function to obtain the string for a particular resource key.
- /// </summary>
- /// <param name="key"></param>
- /// <returns></returns>
- private string GetResource(string key)
- {
- Assert(key != null);
-
- return Environment.GetResourceString(key);
+ Debug.Assert(condition);
}
/// <summary>
@@ -2050,46 +1969,5 @@ namespace System.Collections.Concurrent
m_enumerator.Reset();
}
}
-
-#if !FEATURE_CORECLR
- /// <summary>
- /// Get the data array to be serialized
- /// </summary>
- [OnSerializing]
- private void OnSerializing(StreamingContext context)
- {
- Tables tables = m_tables;
-
- // save the data into the serialization array to be saved
- m_serializationArray = ToArray();
- m_serializationConcurrencyLevel = tables.m_locks.Length;
- m_serializationCapacity = tables.m_buckets.Length;
- m_comparer = (IEqualityComparer<TKey>)HashHelpers.GetEqualityComparerForSerialization(tables.m_comparer);
- }
-
- /// <summary>
- /// Construct the dictionary from a previously serialized one
- /// </summary>
- [OnDeserialized]
- private void OnDeserialized(StreamingContext context)
- {
- KeyValuePair<TKey, TValue>[] array = m_serializationArray;
-
- var buckets = new Node[m_serializationCapacity];
- var countPerLock = new int[m_serializationConcurrencyLevel];
-
- var locks = new object[m_serializationConcurrencyLevel];
- for (int i = 0; i < locks.Length; i++)
- {
- locks[i] = new object();
- }
-
- m_tables = new Tables(buckets, locks, countPerLock, m_comparer);
-
- InitializeFromCollection(array);
- m_serializationArray = null;
-
- }
-#endif
}
}
diff --git a/src/mscorlib/src/System/Collections/Concurrent/ConcurrentQueue.cs b/src/mscorlib/src/System/Collections/Concurrent/ConcurrentQueue.cs
index 9164eadad1..7aa5971690 100644
--- a/src/mscorlib/src/System/Collections/Concurrent/ConcurrentQueue.cs
+++ b/src/mscorlib/src/System/Collections/Concurrent/ConcurrentQueue.cs
@@ -38,7 +38,6 @@ namespace System.Collections.Concurrent
[ComVisible(false)]
[DebuggerDisplay("Count = {Count}")]
[DebuggerTypeProxy(typeof(SystemCollectionsConcurrent_ProducerConsumerCollectionDebugView<>))]
- [HostProtection(Synchronization = true, ExternalThreading = true)]
[Serializable]
public class ConcurrentQueue<T> : IProducerConsumerCollection<T>, IReadOnlyCollection<T>
{
@@ -77,7 +76,7 @@ namespace System.Collections.Concurrent
int index = 0;
foreach (T element in collection)
{
- Contract.Assert(index >= 0 && index < SEGMENT_SIZE);
+ Debug.Assert(index >= 0 && index < SEGMENT_SIZE);
localTail.UnsafeAdd(element);
index++;
@@ -103,7 +102,7 @@ namespace System.Collections.Concurrent
{
if (collection == null)
{
- throw new ArgumentNullException("collection");
+ throw new ArgumentNullException(nameof(collection));
}
InitializeFromCollection(collection);
@@ -125,7 +124,7 @@ namespace System.Collections.Concurrent
[OnDeserialized]
private void OnDeserialized(StreamingContext context)
{
- Contract.Assert(m_serializationArray != null);
+ Debug.Assert(m_serializationArray != null);
InitializeFromCollection(m_serializationArray);
m_serializationArray = null;
}
@@ -160,7 +159,7 @@ namespace System.Collections.Concurrent
// Validate arguments.
if (array == null)
{
- throw new ArgumentNullException("array");
+ throw new ArgumentNullException(nameof(array));
}
// We must be careful not to corrupt the array, so we will first accumulate an
@@ -441,7 +440,7 @@ namespace System.Collections.Concurrent
{
if (array == null)
{
- throw new ArgumentNullException("array");
+ throw new ArgumentNullException(nameof(array));
}
// We must be careful not to corrupt the array, so we will first accumulate an
@@ -689,7 +688,7 @@ namespace System.Collections.Concurrent
m_array = new T[SEGMENT_SIZE];
m_state = new VolatileBool[SEGMENT_SIZE]; //all initialized to false
m_high = -1;
- Contract.Assert(index >= 0);
+ Debug.Assert(index >= 0);
m_index = index;
m_source = source;
}
@@ -721,7 +720,7 @@ namespace System.Collections.Concurrent
/// <param name="value"></param>
internal void UnsafeAdd(T value)
{
- Contract.Assert(m_high < SEGMENT_SIZE - 1);
+ Debug.Assert(m_high < SEGMENT_SIZE - 1);
m_high++;
m_array[m_high] = value;
m_state[m_high].m_value = true;
@@ -737,7 +736,7 @@ namespace System.Collections.Concurrent
/// <returns>the reference to the new Segment</returns>
internal Segment UnsafeGrow()
{
- Contract.Assert(m_high >= SEGMENT_SIZE - 1);
+ Debug.Assert(m_high >= SEGMENT_SIZE - 1);
Segment newSegment = new Segment(m_index + 1, m_source); //m_index is Int64, we don't need to worry about overflow
m_next = newSegment;
return newSegment;
@@ -753,7 +752,7 @@ namespace System.Collections.Concurrent
//no CAS is needed, since there is no contention (other threads are blocked, busy waiting)
Segment newSegment = new Segment(m_index + 1, m_source); //m_index is Int64, we don't need to worry about overflow
m_next = newSegment;
- Contract.Assert(m_source.m_tail == this);
+ Debug.Assert(m_source.m_tail == this);
m_source.m_tail = m_next;
}
@@ -860,7 +859,7 @@ namespace System.Collections.Concurrent
{
spinLocal.SpinOnce();
}
- Contract.Assert(m_source.m_head == this);
+ Debug.Assert(m_source.m_head == this);
m_source.m_head = m_next;
}
return true;
diff --git a/src/mscorlib/src/System/Collections/Concurrent/ConcurrentStack.cs b/src/mscorlib/src/System/Collections/Concurrent/ConcurrentStack.cs
index 15d4176cff..c36d96c26c 100644
--- a/src/mscorlib/src/System/Collections/Concurrent/ConcurrentStack.cs
+++ b/src/mscorlib/src/System/Collections/Concurrent/ConcurrentStack.cs
@@ -45,10 +45,6 @@ namespace System.Collections.Concurrent
/// </remarks>
[DebuggerDisplay("Count = {Count}")]
[DebuggerTypeProxy(typeof(SystemCollectionsConcurrent_ProducerConsumerCollectionDebugView<>))]
- [HostProtection(Synchronization = true, ExternalThreading = true)]
-#if !FEATURE_CORECLR
- [Serializable]
-#endif //!FEATURE_CORECLR
public class ConcurrentStack<T> : IProducerConsumerCollection<T>, IReadOnlyCollection<T>
{
/// <summary>
@@ -70,15 +66,8 @@ namespace System.Collections.Concurrent
}
}
-#if !FEATURE_CORECLR
- [NonSerialized]
-#endif //!FEATURE_CORECLR
private volatile Node m_head; // The stack is a singly linked list, and only remembers the head.
-#if !FEATURE_CORECLR
- private T[] m_serializationArray; // Used for custom serialization.
-#endif //!FEATURE_CORECLR
-
private const int BACKOFF_MAX_YIELDS = 8; // Arbitrary number to cap backoff.
/// <summary>
@@ -101,7 +90,7 @@ namespace System.Collections.Concurrent
{
if (collection == null)
{
- throw new ArgumentNullException("collection");
+ throw new ArgumentNullException(nameof(collection));
}
InitializeFromCollection(collection);
}
@@ -124,50 +113,6 @@ namespace System.Collections.Concurrent
m_head = lastNode;
}
-#if !FEATURE_CORECLR
- /// <summary>
- /// Get the data array to be serialized
- /// </summary>
- [OnSerializing]
- private void OnSerializing(StreamingContext context)
- {
- // save the data into the serialization array to be saved
- m_serializationArray = ToArray();
- }
-
- /// <summary>
- /// Construct the stack from a previously seiralized one
- /// </summary>
- [OnDeserialized]
- private void OnDeserialized(StreamingContext context)
- {
- Contract.Assert(m_serializationArray != null);
- // Add the elements to our stack. We need to add them from head-to-tail, to
- // preserve the original ordering of the stack before serialization.
- Node prevNode = null;
- Node head = null;
- for (int i = 0; i < m_serializationArray.Length; i++)
- {
- Node currNode = new Node(m_serializationArray[i]);
-
- if (prevNode == null)
- {
- head = currNode;
- }
- else
- {
- prevNode.m_next = currNode;
- }
-
- prevNode = currNode;
- }
-
- m_head = head;
- m_serializationArray = null;
- }
-#endif //!FEATURE_CORECLR
-
-
/// <summary>
/// Gets a value that indicates whether the <see cref="ConcurrentStack{T}"/> is empty.
/// </summary>
@@ -221,7 +166,6 @@ namespace System.Collections.Concurrent
}
}
-
/// <summary>
/// Gets a value indicating whether access to the <see cref="T:System.Collections.ICollection"/> is
/// synchronized with the SyncRoot.
@@ -293,7 +237,7 @@ namespace System.Collections.Concurrent
// Validate arguments.
if (array == null)
{
- throw new ArgumentNullException("array");
+ throw new ArgumentNullException(nameof(array));
}
// We must be careful not to corrupt the array, so we will first accumulate an
@@ -327,7 +271,7 @@ namespace System.Collections.Concurrent
{
if (array == null)
{
- throw new ArgumentNullException("array");
+ throw new ArgumentNullException(nameof(array));
}
// We must be careful not to corrupt the array, so we will first accumulate an
@@ -379,7 +323,7 @@ namespace System.Collections.Concurrent
{
if (items == null)
{
- throw new ArgumentNullException("items");
+ throw new ArgumentNullException(nameof(items));
}
PushRange(items, 0, items.Length);
}
@@ -455,13 +399,6 @@ namespace System.Collections.Concurrent
}
while (Interlocked.CompareExchange(
ref m_head, head, tail.m_next) != tail.m_next);
-
-#if !FEATURE_CORECLR
- if (CDSCollectionETWBCLProvider.Log.IsEnabled())
- {
- CDSCollectionETWBCLProvider.Log.ConcurrentStack_FastPushFailed(spin.Count);
- }
-#endif // !FEATURE_CORECLR
}
/// <summary>
@@ -471,16 +408,16 @@ namespace System.Collections.Concurrent
{
if (items == null)
{
- throw new ArgumentNullException("items");
+ throw new ArgumentNullException(nameof(items));
}
if (count < 0)
{
- throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ConcurrentStack_PushPopRange_CountOutOfRange"));
+ throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ConcurrentStack_PushPopRange_CountOutOfRange"));
}
int length = items.Length;
if (startIndex >= length || startIndex < 0)
{
- throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ConcurrentStack_PushPopRange_StartOutOfRange"));
+ throw new ArgumentOutOfRangeException(nameof(startIndex), Environment.GetResourceString("ConcurrentStack_PushPopRange_StartOutOfRange"));
}
if (length - count < startIndex) //instead of (startIndex + count > items.Length) to prevent overflow
{
@@ -584,7 +521,7 @@ namespace System.Collections.Concurrent
{
if (items == null)
{
- throw new ArgumentNullException("items");
+ throw new ArgumentNullException(nameof(items));
}
return TryPopRange(items, 0, items.Length);
@@ -683,12 +620,6 @@ namespace System.Collections.Concurrent
// Is the stack empty?
if (head == null)
{
-#if !FEATURE_CORECLR
- if (count == 1 && CDSCollectionETWBCLProvider.Log.IsEnabled())
- {
- CDSCollectionETWBCLProvider.Log.ConcurrentStack_FastPopFailed(spin.Count);
- }
-#endif //!FEATURE_CORECLR
poppedHead = null;
return 0;
}
@@ -702,12 +633,6 @@ namespace System.Collections.Concurrent
// Try to swap the new head. If we succeed, break out of the loop.
if (Interlocked.CompareExchange(ref m_head, next.m_next, head) == head)
{
-#if !FEATURE_CORECLR
- if (count == 1 && CDSCollectionETWBCLProvider.Log.IsEnabled())
- {
- CDSCollectionETWBCLProvider.Log.ConcurrentStack_FastPopFailed(spin.Count);
- }
-#endif //!FEATURE_CORECLR
// Return the popped Node.
poppedHead = head;
return nodesCount;
diff --git a/src/mscorlib/src/System/Collections/Concurrent/IProducerConsumerCollection.cs b/src/mscorlib/src/System/Collections/Concurrent/IProducerConsumerCollection.cs
index a74f69069a..56be7759c9 100644
--- a/src/mscorlib/src/System/Collections/Concurrent/IProducerConsumerCollection.cs
+++ b/src/mscorlib/src/System/Collections/Concurrent/IProducerConsumerCollection.cs
@@ -97,7 +97,7 @@ namespace System.Collections.Concurrent
{
if (collection == null)
{
- throw new ArgumentNullException("collection");
+ throw new ArgumentNullException(nameof(collection));
}
m_collection = collection;
diff --git a/src/mscorlib/src/System/Collections/Concurrent/OrderablePartitioner.cs b/src/mscorlib/src/System/Collections/Concurrent/OrderablePartitioner.cs
index 02263b7f97..33e3c88e9a 100644
--- a/src/mscorlib/src/System/Collections/Concurrent/OrderablePartitioner.cs
+++ b/src/mscorlib/src/System/Collections/Concurrent/OrderablePartitioner.cs
@@ -61,7 +61,6 @@ namespace System.Collections.Concurrent
/// </ol>
/// </para>
/// </remarks>
- [HostProtection(Synchronization = true, ExternalThreading = true)]
public abstract class OrderablePartitioner<TSource> : Partitioner<TSource>
{
/// <summary>
diff --git a/src/mscorlib/src/System/Collections/Concurrent/Partitioner.cs b/src/mscorlib/src/System/Collections/Concurrent/Partitioner.cs
index 3d54c1471b..0192b1942c 100644
--- a/src/mscorlib/src/System/Collections/Concurrent/Partitioner.cs
+++ b/src/mscorlib/src/System/Collections/Concurrent/Partitioner.cs
@@ -44,7 +44,6 @@ namespace System.Collections.Concurrent
/// </ol>
/// </para>
/// </remarks>
- [HostProtection(Synchronization = true, ExternalThreading = true)]
public abstract class Partitioner<TSource>
{
/// <summary>
diff --git a/src/mscorlib/src/System/Collections/Concurrent/PartitionerStatic.cs b/src/mscorlib/src/System/Collections/Concurrent/PartitionerStatic.cs
index 2169c6dee7..9b36c053ad 100644
--- a/src/mscorlib/src/System/Collections/Concurrent/PartitionerStatic.cs
+++ b/src/mscorlib/src/System/Collections/Concurrent/PartitionerStatic.cs
@@ -14,6 +14,7 @@
using System.Collections.Generic;
using System.Security.Permissions;
using System.Threading;
+using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
@@ -26,9 +27,6 @@ namespace System.Collections.Concurrent
/// non-blocking. These behaviors can be overridden via this enumeration.
/// </summary>
[Flags]
-#if !FEATURE_CORECLR
- [Serializable]
-#endif
public enum EnumerablePartitionerOptions
{
/// <summary>
@@ -71,7 +69,6 @@ namespace System.Collections.Concurrent
/// thread.
/// </para>
/// </remarks>
- [HostProtection(Synchronization = true, ExternalThreading = true)]
public static class Partitioner
{
/// <summary>
@@ -91,7 +88,7 @@ namespace System.Collections.Concurrent
{
if (list == null)
{
- throw new ArgumentNullException("list");
+ throw new ArgumentNullException(nameof(list));
}
if (loadBalance)
{
@@ -122,7 +119,7 @@ namespace System.Collections.Concurrent
if (array == null)
{
- throw new ArgumentNullException("array");
+ throw new ArgumentNullException(nameof(array));
}
if (loadBalance)
{
@@ -172,11 +169,11 @@ namespace System.Collections.Concurrent
{
if (source == null)
{
- throw new ArgumentNullException("source");
+ throw new ArgumentNullException(nameof(source));
}
if ((partitionerOptions & (~EnumerablePartitionerOptions.NoBuffering)) != 0)
- throw new ArgumentOutOfRangeException("partitionerOptions");
+ throw new ArgumentOutOfRangeException(nameof(partitionerOptions));
return (new DynamicPartitionerForIEnumerable<TSource>(source, partitionerOptions));
}
@@ -194,7 +191,7 @@ namespace System.Collections.Concurrent
// load balancing on a busy system if you make it higher than 1.
int coreOversubscriptionRate = 3;
- if (toExclusive <= fromInclusive) throw new ArgumentOutOfRangeException("toExclusive");
+ if (toExclusive <= fromInclusive) throw new ArgumentOutOfRangeException(nameof(toExclusive));
long rangeSize = (toExclusive - fromInclusive) /
(PlatformHelper.ProcessorCount * coreOversubscriptionRate);
if (rangeSize == 0) rangeSize = 1;
@@ -212,8 +209,8 @@ namespace System.Collections.Concurrent
/// less than or equal to 0.</exception>
public static OrderablePartitioner<Tuple<long, long>> Create(long fromInclusive, long toExclusive, long rangeSize)
{
- if (toExclusive <= fromInclusive) throw new ArgumentOutOfRangeException("toExclusive");
- if (rangeSize <= 0) throw new ArgumentOutOfRangeException("rangeSize");
+ if (toExclusive <= fromInclusive) throw new ArgumentOutOfRangeException(nameof(toExclusive));
+ if (rangeSize <= 0) throw new ArgumentOutOfRangeException(nameof(rangeSize));
return Partitioner.Create(CreateRanges(fromInclusive, toExclusive, rangeSize), EnumerablePartitionerOptions.NoBuffering); // chunk one range at a time
}
@@ -251,7 +248,7 @@ namespace System.Collections.Concurrent
// load balancing on a busy system if you make it higher than 1.
int coreOversubscriptionRate = 3;
- if (toExclusive <= fromInclusive) throw new ArgumentOutOfRangeException("toExclusive");
+ if (toExclusive <= fromInclusive) throw new ArgumentOutOfRangeException(nameof(toExclusive));
int rangeSize = (toExclusive - fromInclusive) /
(PlatformHelper.ProcessorCount * coreOversubscriptionRate);
if (rangeSize == 0) rangeSize = 1;
@@ -269,8 +266,8 @@ namespace System.Collections.Concurrent
/// less than or equal to 0.</exception>
public static OrderablePartitioner<Tuple<int, int>> Create(int fromInclusive, int toExclusive, int rangeSize)
{
- if (toExclusive <= fromInclusive) throw new ArgumentOutOfRangeException("toExclusive");
- if (rangeSize <= 0) throw new ArgumentOutOfRangeException("rangeSize");
+ if (toExclusive <= fromInclusive) throw new ArgumentOutOfRangeException(nameof(toExclusive));
+ if (rangeSize <= 0) throw new ArgumentOutOfRangeException(nameof(rangeSize));
return Partitioner.Create(CreateRanges(fromInclusive, toExclusive, rangeSize), EnumerablePartitionerOptions.NoBuffering); // chunk one range at a time
}
@@ -431,7 +428,7 @@ namespace System.Collections.Concurrent
//perform deferred allocating of the local variables.
if (m_localOffset == null)
{
- Contract.Assert(m_currentChunkSize == null);
+ Debug.Assert(m_currentChunkSize == null);
m_localOffset = new SharedInt(-1);
m_currentChunkSize = new SharedInt(0);
m_doublingCountdown = CHUNK_DOUBLING_RATE;
@@ -449,7 +446,7 @@ namespace System.Collections.Concurrent
{
// The second part of the || condition is necessary to handle the case when MoveNext() is called
// after a previous MoveNext call returned false.
- Contract.Assert(m_localOffset.Value == m_currentChunkSize.Value - 1 || m_currentChunkSize.Value == 0);
+ Debug.Assert(m_localOffset.Value == m_currentChunkSize.Value - 1 || m_currentChunkSize.Value == 0);
//set the requested chunk size to a proper value
int requestedChunkSize;
@@ -470,11 +467,11 @@ namespace System.Collections.Concurrent
// Decrement your doubling countdown
m_doublingCountdown--;
- Contract.Assert(requestedChunkSize > 0 && requestedChunkSize <= m_maxChunkSize);
+ Debug.Assert(requestedChunkSize > 0 && requestedChunkSize <= m_maxChunkSize);
//GrabNextChunk will update the value of m_currentChunkSize
if (GrabNextChunk(requestedChunkSize))
{
- Contract.Assert(m_currentChunkSize.Value <= requestedChunkSize && m_currentChunkSize.Value > 0);
+ Debug.Assert(m_currentChunkSize.Value <= requestedChunkSize && m_currentChunkSize.Value > 0);
m_localOffset.Value = 0;
return true;
}
@@ -517,7 +514,7 @@ namespace System.Collections.Concurrent
{
if (partitionCount <= 0)
{
- throw new ArgumentOutOfRangeException("partitionCount");
+ throw new ArgumentOutOfRangeException(nameof(partitionCount));
}
IEnumerator<KeyValuePair<long, TSource>>[] partitions
= new IEnumerator<KeyValuePair<long, TSource>>[partitionCount];
@@ -715,10 +712,10 @@ namespace System.Collections.Concurrent
/// </returns>
internal bool GrabChunk_Single(KeyValuePair<long,TSource>[] destArray, int requestedChunkSize, ref int actualNumElementsGrabbed)
{
- Contract.Assert(m_useSingleChunking, "Expected m_useSingleChecking to be true");
- Contract.Assert(requestedChunkSize == 1, "Got requested chunk size of " + requestedChunkSize + " when single-chunking was on");
- Contract.Assert(actualNumElementsGrabbed == 0, "Expected actualNumElementsGrabbed == 0, instead it is " + actualNumElementsGrabbed);
- Contract.Assert(destArray.Length == 1, "Expected destArray to be of length 1, instead its length is " + destArray.Length);
+ Debug.Assert(m_useSingleChunking, "Expected m_useSingleChecking to be true");
+ Debug.Assert(requestedChunkSize == 1, "Got requested chunk size of " + requestedChunkSize + " when single-chunking was on");
+ Debug.Assert(actualNumElementsGrabbed == 0, "Expected actualNumElementsGrabbed == 0, instead it is " + actualNumElementsGrabbed);
+ Debug.Assert(destArray.Length == 1, "Expected destArray to be of length 1, instead its length is " + destArray.Length);
lock (m_sharedLock)
{
@@ -764,8 +761,8 @@ namespace System.Collections.Concurrent
/// </returns>
internal bool GrabChunk_Buffered(KeyValuePair<long,TSource>[] destArray, int requestedChunkSize, ref int actualNumElementsGrabbed)
{
- Contract.Assert(requestedChunkSize > 0);
- Contract.Assert(!m_useSingleChunking, "Did not expect to be in single-chunking mode");
+ Debug.Assert(requestedChunkSize > 0);
+ Debug.Assert(!m_useSingleChunking, "Did not expect to be in single-chunking mode");
TryCopyFromFillBuffer(destArray, requestedChunkSize, ref actualNumElementsGrabbed);
@@ -803,7 +800,7 @@ namespace System.Collections.Concurrent
while( m_activeCopiers > 0) sw.SpinOnce();
}
- Contract.Assert(m_sharedIndex != null); //already been allocated in MoveNext() before calling GrabNextChunk
+ Debug.Assert(m_sharedIndex != null); //already been allocated in MoveNext() before calling GrabNextChunk
// Now's the time to actually enumerate the source
@@ -940,7 +937,7 @@ namespace System.Collections.Concurrent
/// </returns>
override protected bool GrabNextChunk(int requestedChunkSize)
{
- Contract.Assert(requestedChunkSize > 0);
+ Debug.Assert(requestedChunkSize > 0);
if (HasNoElementsLeft)
{
@@ -973,8 +970,8 @@ namespace System.Collections.Concurrent
{
//we only set it from false to true once
//we should never set it back in any circumstances
- Contract.Assert(value);
- Contract.Assert(!m_hasNoElementsLeft.Value);
+ Debug.Assert(value);
+ Debug.Assert(!m_hasNoElementsLeft.Value);
m_hasNoElementsLeft.Value = true;
}
}
@@ -988,8 +985,8 @@ namespace System.Collections.Concurrent
{
throw new InvalidOperationException(Environment.GetResourceString("PartitionerStatic_CurrentCalledBeforeMoveNext"));
}
- Contract.Assert(m_localList != null);
- Contract.Assert(m_localOffset.Value >= 0 && m_localOffset.Value < m_currentChunkSize.Value);
+ Debug.Assert(m_localList != null);
+ Debug.Assert(m_localOffset.Value >= 0 && m_localOffset.Value < m_currentChunkSize.Value);
return (m_localList[m_localOffset.Value]);
}
}
@@ -1053,7 +1050,7 @@ namespace System.Collections.Concurrent
{
if (partitionCount <= 0)
{
- throw new ArgumentOutOfRangeException("partitionCount");
+ throw new ArgumentOutOfRangeException(nameof(partitionCount));
}
IEnumerator<KeyValuePair<long, TSource>>[] partitions
= new IEnumerator<KeyValuePair<long, TSource>>[partitionCount];
@@ -1127,11 +1124,11 @@ namespace System.Collections.Concurrent
/// </returns>
override protected bool GrabNextChunk(int requestedChunkSize)
{
- Contract.Assert(requestedChunkSize > 0);
+ Debug.Assert(requestedChunkSize > 0);
while (!HasNoElementsLeft)
{
- Contract.Assert(m_sharedIndex != null);
+ Debug.Assert(m_sharedIndex != null);
// use the new Volatile.Read method because it is cheaper than Interlocked.Read on AMD64 architecture
long oldSharedIndex = Volatile.Read(ref m_sharedIndex.Value);
@@ -1173,13 +1170,13 @@ namespace System.Collections.Concurrent
{
get
{
- Contract.Assert(m_sharedIndex != null);
+ Debug.Assert(m_sharedIndex != null);
// use the new Volatile.Read method because it is cheaper than Interlocked.Read on AMD64 architecture
return Volatile.Read(ref m_sharedIndex.Value) >= SourceCount - 1;
}
set
{
- Contract.Assert(false);
+ Debug.Assert(false);
}
}
@@ -1268,7 +1265,7 @@ namespace System.Collections.Concurrent
throw new InvalidOperationException(Environment.GetResourceString("PartitionerStatic_CurrentCalledBeforeMoveNext"));
}
- Contract.Assert(m_localOffset.Value >= 0 && m_localOffset.Value < m_currentChunkSize.Value);
+ Debug.Assert(m_localOffset.Value >= 0 && m_localOffset.Value < m_currentChunkSize.Value);
return new KeyValuePair<long, TSource>(m_startIndex + m_localOffset.Value,
m_sharedReader[m_startIndex + m_localOffset.Value]);
}
@@ -1352,7 +1349,7 @@ namespace System.Collections.Concurrent
throw new InvalidOperationException(Environment.GetResourceString("PartitionerStatic_CurrentCalledBeforeMoveNext"));
}
- Contract.Assert(m_localOffset.Value >= 0 && m_localOffset.Value < m_currentChunkSize.Value);
+ Debug.Assert(m_localOffset.Value >= 0 && m_localOffset.Value < m_currentChunkSize.Value);
return new KeyValuePair<long, TSource>(m_startIndex + m_localOffset.Value,
m_sharedReader[m_startIndex + m_localOffset.Value]);
}
@@ -1417,7 +1414,7 @@ namespace System.Collections.Concurrent
{
if (partitionCount <= 0)
{
- throw new ArgumentOutOfRangeException("partitionCount");
+ throw new ArgumentOutOfRangeException(nameof(partitionCount));
}
int quotient, remainder;
@@ -1539,7 +1536,7 @@ namespace System.Collections.Concurrent
internal StaticIndexRangePartitionerForIList(IList<TSource> list)
: base()
{
- Contract.Assert(list != null);
+ Debug.Assert(list != null);
m_list = list;
}
override protected int SourceCount
@@ -1565,7 +1562,7 @@ namespace System.Collections.Concurrent
internal StaticIndexRangePartitionForIList(IList<TSource> list, int startIndex, int endIndex)
: base(startIndex, endIndex)
{
- Contract.Assert(startIndex >= 0 && endIndex <= list.Count - 1);
+ Debug.Assert(startIndex >= 0 && endIndex <= list.Count - 1);
m_list = list;
}
@@ -1579,7 +1576,7 @@ namespace System.Collections.Concurrent
throw new InvalidOperationException(Environment.GetResourceString("PartitionerStatic_CurrentCalledBeforeMoveNext"));
}
- Contract.Assert(m_offset >= m_startIndex && m_offset <= m_endIndex);
+ Debug.Assert(m_offset >= m_startIndex && m_offset <= m_endIndex);
return (new KeyValuePair<long, TSource>(m_offset, m_list[m_offset]));
}
}
@@ -1597,7 +1594,7 @@ namespace System.Collections.Concurrent
internal StaticIndexRangePartitionerForArray(TSource[] array)
: base()
{
- Contract.Assert(array != null);
+ Debug.Assert(array != null);
m_array = array;
}
override protected int SourceCount
@@ -1622,7 +1619,7 @@ namespace System.Collections.Concurrent
internal StaticIndexRangePartitionForArray(TSource[] array, int startIndex, int endIndex)
: base(startIndex, endIndex)
{
- Contract.Assert(startIndex >= 0 && endIndex <= array.Length - 1);
+ Debug.Assert(startIndex >= 0 && endIndex <= array.Length - 1);
m_array = array;
}
@@ -1636,7 +1633,7 @@ namespace System.Collections.Concurrent
throw new InvalidOperationException(Environment.GetResourceString("PartitionerStatic_CurrentCalledBeforeMoveNext"));
}
- Contract.Assert(m_offset >= m_startIndex && m_offset <= m_endIndex);
+ Debug.Assert(m_offset >= m_startIndex && m_offset <= m_endIndex);
return (new KeyValuePair<long, TSource>(m_offset, m_array[m_offset]));
}
}
@@ -1704,30 +1701,15 @@ namespace System.Collections.Concurrent
if (typeof(TSource).IsValueType)
{
-#if !FEATURE_CORECLR // Marshal.SizeOf is not supported in CoreCLR
-
- if (typeof(TSource).StructLayoutAttribute.Value == LayoutKind.Explicit)
- {
- chunkSize = Math.Max(1, DEFAULT_BYTES_PER_CHUNK / Marshal.SizeOf(typeof(TSource)));
- }
- else
- {
- // We choose '128' because this ensures, no matter the actual size of the value type,
- // the total bytes used will be a multiple of 128. This ensures it's cache aligned.
- chunkSize = 128;
- }
-#else
chunkSize = 128;
-#endif
}
else
{
- Contract.Assert((DEFAULT_BYTES_PER_CHUNK % IntPtr.Size) == 0, "bytes per chunk should be a multiple of pointer size");
+ Debug.Assert((DEFAULT_BYTES_PER_CHUNK % IntPtr.Size) == 0, "bytes per chunk should be a multiple of pointer size");
chunkSize = (DEFAULT_BYTES_PER_CHUNK / IntPtr.Size);
}
return chunkSize;
}
#endregion
-
}
}