diff options
Diffstat (limited to 'src/mscorlib/src/System/Threading/Tasks/Parallel.cs')
-rw-r--r-- | src/mscorlib/src/System/Threading/Tasks/Parallel.cs | 229 |
1 files changed, 114 insertions, 115 deletions
diff --git a/src/mscorlib/src/System/Threading/Tasks/Parallel.cs b/src/mscorlib/src/System/Threading/Tasks/Parallel.cs index 5ec2ae33c0..7808943870 100644 --- a/src/mscorlib/src/System/Threading/Tasks/Parallel.cs +++ b/src/mscorlib/src/System/Threading/Tasks/Parallel.cs @@ -98,7 +98,7 @@ namespace System.Threading.Tasks set { if ((value == 0) || (value < -1)) - throw new ArgumentOutOfRangeException("MaxDegreeOfParallelism"); + throw new ArgumentOutOfRangeException(nameof(MaxDegreeOfParallelism)); m_maxDegreeOfParallelism = value; } } @@ -142,7 +142,6 @@ namespace System.Threading.Tasks /// The <see cref="T:System.Threading.Tasks.Parallel"/> class provides library-based data parallel replacements /// for common operations such as for loops, for each loops, and execution of a set of statements. /// </remarks> - [HostProtection(Synchronization = true, ExternalThreading = true)] public static class Parallel { // static counter for generating unique Fork/Join Context IDs to be used in ETW events @@ -208,11 +207,11 @@ namespace System.Threading.Tasks { if (actions == null) { - throw new ArgumentNullException("actions"); + throw new ArgumentNullException(nameof(actions)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } // Throw an ODE if we're passed a disposed CancellationToken. @@ -423,7 +422,7 @@ namespace System.Threading.Tasks { if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } return ForWorker<object>( @@ -452,7 +451,7 @@ namespace System.Threading.Tasks { if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } return ForWorker64<object>( @@ -491,11 +490,11 @@ namespace System.Threading.Tasks { if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } return ForWorker<object>( @@ -534,11 +533,11 @@ namespace System.Threading.Tasks { if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } return ForWorker64<object>( @@ -590,7 +589,7 @@ namespace System.Threading.Tasks { if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } return ForWorker<object>( @@ -620,7 +619,7 @@ namespace System.Threading.Tasks { if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } return ForWorker64<object>( @@ -661,11 +660,11 @@ namespace System.Threading.Tasks { if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } return ForWorker<object>( @@ -707,11 +706,11 @@ namespace System.Threading.Tasks { if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } return ForWorker64<object>( @@ -765,15 +764,15 @@ namespace System.Threading.Tasks { if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (localInit == null) { - throw new ArgumentNullException("localInit"); + throw new ArgumentNullException(nameof(localInit)); } if (localFinally == null) { - throw new ArgumentNullException("localFinally"); + throw new ArgumentNullException(nameof(localFinally)); } return ForWorker( @@ -827,15 +826,15 @@ namespace System.Threading.Tasks { if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (localInit == null) { - throw new ArgumentNullException("localInit"); + throw new ArgumentNullException(nameof(localInit)); } if (localFinally == null) { - throw new ArgumentNullException("localFinally"); + throw new ArgumentNullException(nameof(localFinally)); } return ForWorker64( @@ -900,19 +899,19 @@ namespace System.Threading.Tasks { if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (localInit == null) { - throw new ArgumentNullException("localInit"); + throw new ArgumentNullException(nameof(localInit)); } if (localFinally == null) { - throw new ArgumentNullException("localFinally"); + throw new ArgumentNullException(nameof(localFinally)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } return ForWorker( @@ -977,19 +976,19 @@ namespace System.Threading.Tasks { if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (localInit == null) { - throw new ArgumentNullException("localInit"); + throw new ArgumentNullException(nameof(localInit)); } if (localFinally == null) { - throw new ArgumentNullException("localFinally"); + throw new ArgumentNullException(nameof(localFinally)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } @@ -1031,9 +1030,9 @@ namespace System.Threading.Tasks Func<int, ParallelLoopState, TLocal, TLocal> bodyWithLocal, Func<TLocal> localInit, Action<TLocal> localFinally) { - Contract.Assert(((body == null ? 0 : 1) + (bodyWithState == null ? 0 : 1) + (bodyWithLocal == null ? 0 : 1)) == 1, + Debug.Assert(((body == null ? 0 : 1) + (bodyWithState == null ? 0 : 1) + (bodyWithLocal == null ? 0 : 1)) == 1, "expected exactly one body function to be supplied"); - Contract.Assert(bodyWithLocal != null || (localInit == null && localFinally == null), + Debug.Assert(bodyWithLocal != null || (localInit == null && localFinally == null), "thread local functions should only be supplied for loops w/ thread local bodies"); // Instantiate our result. Specifics will be filled in later. @@ -1157,12 +1156,12 @@ namespace System.Threading.Tasks if (bodyWithState != null) { - Contract.Assert(sharedPStateFlags != null); + Debug.Assert(sharedPStateFlags != null); state = new ParallelLoopState32(sharedPStateFlags); } else if (bodyWithLocal != null) { - Contract.Assert(sharedPStateFlags != null); + Debug.Assert(sharedPStateFlags != null); state = new ParallelLoopState32(sharedPStateFlags); if (localInit != null) { @@ -1346,9 +1345,9 @@ namespace System.Threading.Tasks Func<long, ParallelLoopState, TLocal, TLocal> bodyWithLocal, Func<TLocal> localInit, Action<TLocal> localFinally) { - Contract.Assert(((body == null ? 0 : 1) + (bodyWithState == null ? 0 : 1) + (bodyWithLocal == null ? 0 : 1)) == 1, + Debug.Assert(((body == null ? 0 : 1) + (bodyWithState == null ? 0 : 1) + (bodyWithLocal == null ? 0 : 1)) == 1, "expected exactly one body function to be supplied"); - Contract.Assert(bodyWithLocal != null || (localInit == null && localFinally == null), + Debug.Assert(bodyWithLocal != null || (localInit == null && localFinally == null), "thread local functions should only be supplied for loops w/ thread local bodies"); // Instantiate our result. Specifics will be filled in later. @@ -1471,12 +1470,12 @@ namespace System.Threading.Tasks if (bodyWithState != null) { - Contract.Assert(sharedPStateFlags != null); + Debug.Assert(sharedPStateFlags != null); state = new ParallelLoopState64(sharedPStateFlags); } else if (bodyWithLocal != null) { - Contract.Assert(sharedPStateFlags != null); + Debug.Assert(sharedPStateFlags != null); state = new ParallelLoopState64(sharedPStateFlags); // If a thread-local selector was supplied, invoke it. Otherwise, use the default. @@ -1656,11 +1655,11 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } return ForEachWorker<TSource, object>( @@ -1701,15 +1700,15 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } return ForEachWorker<TSource, object>( @@ -1741,11 +1740,11 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } return ForEachWorker<TSource, object>( @@ -1788,15 +1787,15 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } return ForEachWorker<TSource, object>( @@ -1828,11 +1827,11 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } return ForEachWorker<TSource, object>( @@ -1875,15 +1874,15 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } return ForEachWorker<TSource, object>( @@ -1936,19 +1935,19 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (localInit == null) { - throw new ArgumentNullException("localInit"); + throw new ArgumentNullException(nameof(localInit)); } if (localFinally == null) { - throw new ArgumentNullException("localFinally"); + throw new ArgumentNullException(nameof(localFinally)); } return ForEachWorker<TSource, TLocal>( @@ -2013,23 +2012,23 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (localInit == null) { - throw new ArgumentNullException("localInit"); + throw new ArgumentNullException(nameof(localInit)); } if (localFinally == null) { - throw new ArgumentNullException("localFinally"); + throw new ArgumentNullException(nameof(localFinally)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } return ForEachWorker<TSource, TLocal>( @@ -2082,19 +2081,19 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (localInit == null) { - throw new ArgumentNullException("localInit"); + throw new ArgumentNullException(nameof(localInit)); } if (localFinally == null) { - throw new ArgumentNullException("localFinally"); + throw new ArgumentNullException(nameof(localFinally)); } return ForEachWorker<TSource, TLocal>( @@ -2158,23 +2157,23 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (localInit == null) { - throw new ArgumentNullException("localInit"); + throw new ArgumentNullException(nameof(localInit)); } if (localFinally == null) { - throw new ArgumentNullException("localFinally"); + throw new ArgumentNullException(nameof(localFinally)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } return ForEachWorker<TSource, TLocal>( @@ -2214,10 +2213,10 @@ namespace System.Threading.Tasks Func<TSource, ParallelLoopState, long, TLocal, TLocal> bodyWithEverything, Func<TLocal> localInit, Action<TLocal> localFinally) { - Contract.Assert(((body == null ? 0 : 1) + (bodyWithState == null ? 0 : 1) + + Debug.Assert(((body == null ? 0 : 1) + (bodyWithState == null ? 0 : 1) + (bodyWithStateAndIndex == null ? 0 : 1) + (bodyWithStateAndLocal == null ? 0 : 1) + (bodyWithEverything == null ? 0 : 1)) == 1, "expected exactly one body function to be supplied"); - Contract.Assert((bodyWithStateAndLocal != null) || (bodyWithEverything != null) || (localInit == null && localFinally == null), + Debug.Assert((bodyWithStateAndLocal != null) || (bodyWithEverything != null) || (localInit == null && localFinally == null), "thread local functions should only be supplied for loops w/ thread local bodies"); // Before getting started, do a quick peek to see if we have been canceled already @@ -2278,8 +2277,8 @@ namespace System.Threading.Tasks Func<TSource, ParallelLoopState, long, TLocal, TLocal> bodyWithEverything, Func<TLocal> localInit, Action<TLocal> localFinally) { - Contract.Assert(array != null); - Contract.Assert(parallelOptions != null, "ForEachWorker(array): parallelOptions is null"); + Debug.Assert(array != null); + Debug.Assert(parallelOptions != null, "ForEachWorker(array): parallelOptions is null"); int from = array.GetLowerBound(0); int to = array.GetUpperBound(0) + 1; @@ -2337,8 +2336,8 @@ namespace System.Threading.Tasks Func<TSource, ParallelLoopState, long, TLocal, TLocal> bodyWithEverything, Func<TLocal> localInit, Action<TLocal> localFinally) { - Contract.Assert(list != null); - Contract.Assert(parallelOptions != null, "ForEachWorker(list): parallelOptions is null"); + Debug.Assert(list != null); + Debug.Assert(parallelOptions != null, "ForEachWorker(list): parallelOptions is null"); if (body != null) { @@ -2416,11 +2415,11 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } return PartitionerForEachWorker<TSource, object>(source, s_defaultParallelOptions, body, null, null, null, null, null, null); @@ -2475,11 +2474,11 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } return PartitionerForEachWorker<TSource, object>(source, s_defaultParallelOptions, null, body, null, null, null, null, null); @@ -2537,11 +2536,11 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (!source.KeysNormalized) @@ -2621,19 +2620,19 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (localInit == null) { - throw new ArgumentNullException("localInit"); + throw new ArgumentNullException(nameof(localInit)); } if (localFinally == null) { - throw new ArgumentNullException("localFinally"); + throw new ArgumentNullException(nameof(localFinally)); } return PartitionerForEachWorker<TSource, TLocal>(source, s_defaultParallelOptions, null, null, null, body, null, localInit, localFinally); @@ -2711,19 +2710,19 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (localInit == null) { - throw new ArgumentNullException("localInit"); + throw new ArgumentNullException(nameof(localInit)); } if (localFinally == null) { - throw new ArgumentNullException("localFinally"); + throw new ArgumentNullException(nameof(localFinally)); } if (!source.KeysNormalized) @@ -2793,15 +2792,15 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } return PartitionerForEachWorker<TSource, object>(source, parallelOptions, body, null, null, null, null, null, null); @@ -2868,15 +2867,15 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } return PartitionerForEachWorker<TSource, object>(source, parallelOptions, null, body, null, null, null, null, null); @@ -2946,15 +2945,15 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } if (!source.KeysNormalized) @@ -3046,23 +3045,23 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (localInit == null) { - throw new ArgumentNullException("localInit"); + throw new ArgumentNullException(nameof(localInit)); } if (localFinally == null) { - throw new ArgumentNullException("localFinally"); + throw new ArgumentNullException(nameof(localFinally)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } return PartitionerForEachWorker<TSource, TLocal>(source, parallelOptions, null, null, null, body, null, localInit, localFinally); @@ -3152,23 +3151,23 @@ namespace System.Threading.Tasks { if (source == null) { - throw new ArgumentNullException("source"); + throw new ArgumentNullException(nameof(source)); } if (body == null) { - throw new ArgumentNullException("body"); + throw new ArgumentNullException(nameof(body)); } if (localInit == null) { - throw new ArgumentNullException("localInit"); + throw new ArgumentNullException(nameof(localInit)); } if (localFinally == null) { - throw new ArgumentNullException("localFinally"); + throw new ArgumentNullException(nameof(localFinally)); } if (parallelOptions == null) { - throw new ArgumentNullException("parallelOptions"); + throw new ArgumentNullException(nameof(parallelOptions)); } if (!source.KeysNormalized) @@ -3191,14 +3190,14 @@ namespace System.Threading.Tasks Func<TLocal> localInit, Action<TLocal> localFinally) { - Contract.Assert(((simpleBody == null ? 0 : 1) + (bodyWithState == null ? 0 : 1) + + Debug.Assert(((simpleBody == null ? 0 : 1) + (bodyWithState == null ? 0 : 1) + (bodyWithStateAndIndex == null ? 0 : 1) + (bodyWithStateAndLocal == null ? 0 : 1) + (bodyWithEverything == null ? 0 : 1)) == 1, "PartitionForEach: expected exactly one body function to be supplied"); - Contract.Assert((bodyWithStateAndLocal != null) || (bodyWithEverything != null) || (localInit == null && localFinally == null), + Debug.Assert((bodyWithStateAndLocal != null) || (bodyWithEverything != null) || (localInit == null && localFinally == null), "PartitionForEach: thread local functions should only be supplied for loops w/ thread local bodies"); OrderablePartitioner<TSource> orderedSource = source as OrderablePartitioner<TSource>; - Contract.Assert((orderedSource != null) || (bodyWithStateAndIndex == null && bodyWithEverything == null), + Debug.Assert((orderedSource != null) || (bodyWithStateAndIndex == null && bodyWithEverything == null), "PartitionForEach: bodies with indices are only allowable for OrderablePartitioner"); if (!source.SupportsDynamicPartitions) @@ -3401,7 +3400,7 @@ namespace System.Threading.Tasks else if (bodyWithStateAndLocal != null) localValue = bodyWithStateAndLocal(t, state, localValue); else - Contract.Assert(false, "PartitionerForEach: illegal body type in Partitioner handler"); + Debug.Assert(false, "PartitionerForEach: illegal body type in Partitioner handler"); // Any break, stop or exception causes us to halt @@ -3576,7 +3575,7 @@ namespace System.Threading.Tasks public bool LimitExceeded() { - Contract.Assert(m_timeLimit != 0, "Probably the default initializer for LoopTimer was used somewhere"); + Debug.Assert(m_timeLimit != 0, "Probably the default initializer for LoopTimer was used somewhere"); // comparing against the next expected time saves an addition operation here // Also we omit the comparison for wrap around here. The only side effect is one extra early yield every 38 days. |