Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ PartitionerForEachWorker< TSource, TLocal >()

static ParallelLoopResult System.Threading.Tasks.Parallel.PartitionerForEachWorker< TSource, TLocal > ( Partitioner< TSource > source,
ParallelOptions parallelOptions,
Action< TSource > simpleBody,
Action< TSource, ParallelLoopState > bodyWithState,
Action< TSource, ParallelLoopState, long > bodyWithStateAndIndex,
Func< TSource, ParallelLoopState, TLocal, TLocal > bodyWithStateAndLocal,
Func< TSource, ParallelLoopState, long, TLocal, TLocal > bodyWithEverything,
Func< TLocal > localInit,
Action< TLocal > localFinally )
inlinestaticprivate

Definition at line 1206 of file Parallel.cs.

1207 {
1209 if (!source.SupportsDynamicPartitions)
1210 {
1212 }
1213 parallelOptions.CancellationToken.ThrowIfCancellationRequested();
1214 int forkJoinContextID = 0;
1215 if (ParallelEtwProvider.Log.IsEnabled())
1216 {
1217 forkJoinContextID = Interlocked.Increment(ref s_forkJoinContextID);
1218 ParallelEtwProvider.Log.ParallelLoopBegin(TaskScheduler.Current.Id, Task.CurrentId.GetValueOrDefault(), forkJoinContextID, ParallelEtwProvider.ForkJoinOperationType.ParallelForEach, 0L, 0L);
1219 }
1220 ParallelLoopStateFlags64 sharedPStateFlags = new ParallelLoopStateFlags64();
1221 ParallelLoopResult result = default(ParallelLoopResult);
1222 OperationCanceledException oce = null;
1223 CancellationTokenRegistration cancellationTokenRegistration = ((!parallelOptions.CancellationToken.CanBeCanceled) ? default(CancellationTokenRegistration) : parallelOptions.CancellationToken.UnsafeRegister((Action<object?>)delegate
1224 {
1225 oce = new OperationCanceledException(parallelOptions.CancellationToken);
1226 sharedPStateFlags.Cancel();
1227 }, (object?)null));
1230 if (orderedSource != null)
1231 {
1232 orderablePartitionerSource = orderedSource.GetOrderableDynamicPartitions();
1233 if (orderablePartitionerSource == null)
1234 {
1236 }
1237 }
1238 else
1239 {
1240 partitionerSource = source.GetDynamicPartitions();
1241 if (partitionerSource == null)
1242 {
1244 }
1245 }
1246 try
1247 {
1248 try
1249 {
1251 {
1253 if (ParallelEtwProvider.Log.IsEnabled())
1254 {
1255 ParallelEtwProvider.Log.ParallelFork(TaskScheduler.Current.Id, Task.CurrentId.GetValueOrDefault(), forkJoinContextID);
1256 }
1257 TLocal val = default(TLocal);
1258 bool flag = false;
1259 try
1260 {
1261 ParallelLoopState64 parallelLoopState = null;
1262 if (bodyWithState != null || bodyWithStateAndIndex != null)
1263 {
1264 parallelLoopState = new ParallelLoopState64(sharedPStateFlags);
1265 }
1266 else if (bodyWithStateAndLocal != null || bodyWithEverything != null)
1267 {
1268 parallelLoopState = new ParallelLoopState64(sharedPStateFlags);
1269 if (localInit != null)
1270 {
1271 val = localInit();
1272 flag = true;
1273 }
1274 }
1276 if (orderedSource != null)
1277 {
1279 if (enumerator == null)
1280 {
1282 }
1283 if (enumerator == null)
1284 {
1286 }
1287 while (enumerator.MoveNext())
1288 {
1289 KeyValuePair<long, TSource> current = enumerator.Current;
1290 long key = current.Key;
1291 TSource value = current.Value;
1292 if (parallelLoopState != null)
1293 {
1294 parallelLoopState.CurrentIteration = key;
1295 }
1296 if (simpleBody != null)
1297 {
1299 }
1300 else if (bodyWithState != null)
1301 {
1303 }
1304 else if (bodyWithStateAndIndex == null)
1305 {
1307 }
1308 else
1309 {
1311 }
1312 if (sharedPStateFlags.ShouldExitLoop(key))
1313 {
1314 break;
1315 }
1317 {
1319 break;
1320 }
1321 }
1322 }
1323 else
1324 {
1326 if (enumerator2 == null)
1327 {
1329 }
1330 if (enumerator2 == null)
1331 {
1333 }
1334 if (parallelLoopState != null)
1335 {
1336 parallelLoopState.CurrentIteration = 0L;
1337 }
1338 while (enumerator2.MoveNext())
1339 {
1340 TSource current2 = enumerator2.Current;
1341 if (simpleBody != null)
1342 {
1344 }
1345 else if (bodyWithState != null)
1346 {
1348 }
1349 else if (bodyWithStateAndLocal != null)
1350 {
1352 }
1353 if (sharedPStateFlags.LoopStateFlags != 0)
1354 {
1355 break;
1356 }
1358 {
1360 break;
1361 }
1362 }
1363 }
1364 }
1365 catch (Exception source2)
1366 {
1367 sharedPStateFlags.SetExceptional();
1369 }
1370 finally
1371 {
1372 if (localFinally != null && flag)
1373 {
1374 localFinally(val);
1375 }
1377 {
1378 disposable2.Dispose();
1379 }
1380 if (ParallelEtwProvider.Log.IsEnabled())
1381 {
1382 ParallelEtwProvider.Log.ParallelJoin(TaskScheduler.Current.Id, Task.CurrentId.GetValueOrDefault(), forkJoinContextID);
1383 }
1384 }
1386 }
1387 finally
1388 {
1389 if (parallelOptions.CancellationToken.CanBeCanceled)
1390 {
1392 }
1393 }
1394 if (oce != null)
1395 {
1396 throw oce;
1397 }
1398 }
1399 catch (AggregateException ex)
1400 {
1401 ThrowSingleCancellationExceptionOrOtherException(ex.InnerExceptions, parallelOptions.CancellationToken, ex);
1402 }
1403 finally
1404 {
1405 int loopStateFlags = sharedPStateFlags.LoopStateFlags;
1406 result._completed = loopStateFlags == 0;
1407 if (((uint)loopStateFlags & 2u) != 0)
1408 {
1409 result._lowestBreakIteration = sharedPStateFlags.LowestBreakIteration;
1410 }
1411 IDisposable disposable = null;
1412 ((orderablePartitionerSource == null) ? (partitionerSource as IDisposable) : (orderablePartitionerSource as IDisposable))?.Dispose();
1413 if (ParallelEtwProvider.Log.IsEnabled())
1414 {
1415 ParallelEtwProvider.Log.ParallelLoopEnd(TaskScheduler.Current.Id, Task.CurrentId.GetValueOrDefault(), forkJoinContextID, 0L);
1416 }
1417 }
1418 return result;
1419 }
static string Parallel_ForEach_NullEnumerator
Definition SR.cs:22
static string Parallel_ForEach_PartitionerNotDynamic
Definition SR.cs:18
static string Parallel_ForEach_PartitionerReturnedNull
Definition SR.cs:20
Definition SR.cs:7
static int ComputeTimeoutPoint(int timeoutLength)
Definition Parallel.cs:443
static void ThrowSingleCancellationExceptionOrOtherException(ICollection exceptions, CancellationToken cancelToken, Exception otherException)
Definition Parallel.cs:1447
static bool CheckTimeoutReached(int timeoutOccursAt)
Definition Parallel.cs:429

References System.Threading.Tasks.Parallel.CheckTimeoutReached(), System.Threading.Tasks.Parallel.ComputeTimeoutPoint(), System.Threading.Tasks.TaskScheduler.Current, System.Threading.Tasks.Task< TResult >.CurrentId, System.Collections.Generic.Dictionary< TKey, TValue >.GetEnumerator(), System.Threading.Interlocked.Increment(), System.key, System.L, System.Threading.Tasks.ParallelEtwProvider.Log, System.SR.Parallel_ForEach_NullEnumerator, System.SR.Parallel_ForEach_PartitionerNotDynamic, System.SR.Parallel_ForEach_PartitionerReturnedNull, System.Threading.Tasks.Parallel.s_forkJoinContextID, System.source, System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(), System.Threading.Tasks.Parallel.ThrowSingleCancellationExceptionOrOtherException(), System.timeout, and System.value.