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

◆ ForWorker64< TLocal >()

static ParallelLoopResult System.Threading.Tasks.Parallel.ForWorker64< TLocal > ( long fromInclusive,
long toExclusive,
ParallelOptions parallelOptions,
Action< long > body,
Action< long, ParallelLoopState > bodyWithState,
Func< long, ParallelLoopState, TLocal, TLocal > bodyWithLocal,
Func< TLocal > localInit,
Action< TLocal > localFinally )
inlinestaticprivate

Definition at line 599 of file Parallel.cs.

600 {
601 ParallelLoopResult result = default(ParallelLoopResult);
603 {
604 result._completed = true;
605 return result;
606 }
607 ParallelLoopStateFlags64 sharedPStateFlags = new ParallelLoopStateFlags64();
608 parallelOptions.CancellationToken.ThrowIfCancellationRequested();
609 int nNumExpectedWorkers = ((parallelOptions.EffectiveMaxConcurrencyLevel == -1) ? Environment.ProcessorCount : parallelOptions.EffectiveMaxConcurrencyLevel);
610 RangeManager rangeManager = new RangeManager(fromInclusive, toExclusive, 1L, nNumExpectedWorkers);
611 OperationCanceledException oce = null;
612 CancellationTokenRegistration cancellationTokenRegistration = ((!parallelOptions.CancellationToken.CanBeCanceled) ? default(CancellationTokenRegistration) : parallelOptions.CancellationToken.UnsafeRegister((Action<object?>)delegate
613 {
614 oce = new OperationCanceledException(parallelOptions.CancellationToken);
615 sharedPStateFlags.Cancel();
616 }, (object?)null));
617 int forkJoinContextID = 0;
618 if (ParallelEtwProvider.Log.IsEnabled())
619 {
620 forkJoinContextID = Interlocked.Increment(ref s_forkJoinContextID);
621 ParallelEtwProvider.Log.ParallelLoopBegin(TaskScheduler.Current.Id, Task.CurrentId.GetValueOrDefault(), forkJoinContextID, ParallelEtwProvider.ForkJoinOperationType.ParallelFor, fromInclusive, toExclusive);
622 }
623 try
624 {
625 try
626 {
627 TaskReplicator.Run(delegate(ref RangeWorker currentWorker, int timeout, out bool replicationDelegateYieldedBeforeCompletion)
628 {
629 if (!currentWorker.IsInitialized)
630 {
631 currentWorker = rangeManager.RegisterNewWorker();
632 }
635 {
636 return;
637 }
638 if (ParallelEtwProvider.Log.IsEnabled())
639 {
640 ParallelEtwProvider.Log.ParallelFork(TaskScheduler.Current.Id, Task.CurrentId.GetValueOrDefault(), forkJoinContextID);
641 }
642 TLocal val = default(TLocal);
643 bool flag = false;
644 try
645 {
646 ParallelLoopState64 parallelLoopState = null;
647 if (bodyWithState != null)
648 {
649 parallelLoopState = new ParallelLoopState64(sharedPStateFlags);
650 }
651 else if (bodyWithLocal != null)
652 {
653 parallelLoopState = new ParallelLoopState64(sharedPStateFlags);
654 if (localInit != null)
655 {
656 val = localInit();
657 flag = true;
658 }
659 }
661 do
662 {
663 if (body != null)
664 {
666 {
667 if (sharedPStateFlags.LoopStateFlags != 0 && sharedPStateFlags.ShouldExitLoop())
668 {
669 break;
670 }
671 body(num2);
672 }
673 }
674 else if (bodyWithState != null)
675 {
676 for (long num3 = nFromInclusiveLocal; num3 < nToExclusiveLocal && (sharedPStateFlags.LoopStateFlags == 0 || !sharedPStateFlags.ShouldExitLoop(num3)); num3++)
677 {
678 parallelLoopState.CurrentIteration = num3;
680 }
681 }
682 else
683 {
684 for (long num4 = nFromInclusiveLocal; num4 < nToExclusiveLocal && (sharedPStateFlags.LoopStateFlags == 0 || !sharedPStateFlags.ShouldExitLoop(num4)); num4++)
685 {
686 parallelLoopState.CurrentIteration = num4;
688 }
689 }
691 {
693 break;
694 }
695 }
696 while (currentWorker.FindNewWork(out nFromInclusiveLocal, out nToExclusiveLocal) && (sharedPStateFlags.LoopStateFlags == 0 || !sharedPStateFlags.ShouldExitLoop(nFromInclusiveLocal)));
697 }
698 catch (Exception source)
699 {
700 sharedPStateFlags.SetExceptional();
702 }
703 finally
704 {
705 if (localFinally != null && flag)
706 {
707 localFinally(val);
708 }
709 if (ParallelEtwProvider.Log.IsEnabled())
710 {
711 ParallelEtwProvider.Log.ParallelJoin(TaskScheduler.Current.Id, Task.CurrentId.GetValueOrDefault(), forkJoinContextID);
712 }
713 }
715 }
716 finally
717 {
718 if (parallelOptions.CancellationToken.CanBeCanceled)
719 {
721 }
722 }
723 if (oce != null)
724 {
725 throw oce;
726 }
727 }
728 catch (AggregateException ex)
729 {
730 ThrowSingleCancellationExceptionOrOtherException(ex.InnerExceptions, parallelOptions.CancellationToken, ex);
731 }
732 finally
733 {
734 int loopStateFlags = sharedPStateFlags.LoopStateFlags;
735 result._completed = loopStateFlags == 0;
736 if (((uint)loopStateFlags & 2u) != 0)
737 {
738 result._lowestBreakIteration = sharedPStateFlags.LowestBreakIteration;
739 }
740 if (ParallelEtwProvider.Log.IsEnabled())
741 {
742 long num = 0L;
743 num = ((loopStateFlags == 0) ? (toExclusive - fromInclusive) : (((loopStateFlags & 2) == 0) ? (-1) : (sharedPStateFlags.LowestBreakIteration - fromInclusive)));
744 ParallelEtwProvider.Log.ParallelLoopEnd(TaskScheduler.Current.Id, Task.CurrentId.GetValueOrDefault(), forkJoinContextID, num);
745 }
746 }
747 return result;
748 }
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.Threading.Interlocked.Increment(), System.L, System.Threading.Tasks.ParallelEtwProvider.Log, System.Environment.ProcessorCount, System.Threading.Tasks.Parallel.s_forkJoinContextID, System.source, System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(), System.Threading.Tasks.Parallel.ThrowSingleCancellationExceptionOrOtherException(), and System.timeout.