// Token: 0x06003F2F RID: 16175 RVA: 0x000EB764 File Offset: 0x000E9964 internal static void Break(int iteration, ParallelLoopStateFlags32 pflags) { int pls_NONE = ParallelLoopStateFlags.PLS_NONE; if (pflags.AtomicLoopStateUpdate(ParallelLoopStateFlags.PLS_BROKEN, ParallelLoopStateFlags.PLS_STOPPED | ParallelLoopStateFlags.PLS_EXCEPTIONAL | ParallelLoopStateFlags.PLS_CANCELED, ref pls_NONE)) { int lowestBreakIteration = pflags.m_lowestBreakIteration; if (iteration < lowestBreakIteration) { SpinWait spinWait = default(SpinWait); while (Interlocked.CompareExchange(ref pflags.m_lowestBreakIteration, iteration, lowestBreakIteration) != lowestBreakIteration) { spinWait.SpinOnce(); lowestBreakIteration = pflags.m_lowestBreakIteration; if (iteration > lowestBreakIteration) { break; } } } return; } if ((pls_NONE & ParallelLoopStateFlags.PLS_STOPPED) != 0) { throw new InvalidOperationException(Environment.GetResourceString("ParallelState_Break_InvalidOperationException_BreakAfterStop")); } }
internal static void Break(int iteration, ParallelLoopStateFlags32 pflags) { int oldState = ParallelLoopStateFlags.PLS_NONE; if (!pflags.AtomicLoopStateUpdate(ParallelLoopStateFlags.PLS_BROKEN, ParallelLoopStateFlags.PLS_STOPPED | ParallelLoopStateFlags.PLS_EXCEPTIONAL | ParallelLoopStateFlags.PLS_CANCELED, ref oldState)) { if ((oldState & ParallelLoopStateFlags.PLS_STOPPED) != 0) { throw new InvalidOperationException(Environment.GetResourceString("ParallelState_Break_InvalidOperationException_BreakAfterStop")); } } else { int comparand = pflags.m_lowestBreakIteration; if (iteration >= comparand) { return; } SpinWait spinWait = new SpinWait(); while (Interlocked.CompareExchange(ref pflags.m_lowestBreakIteration, iteration, comparand) != comparand) { spinWait.SpinOnce(); comparand = pflags.m_lowestBreakIteration; if (iteration > comparand) { break; } } } }
// Helper method to avoid repeating Break() logic between ParallelState32 and ParallelState32<TLocal> internal static void Break(int iteration, ParallelLoopStateFlags32 parallelFlags) { // Attempt to change state from "not stopped or broken or canceled or exceptional" to "broken". if ( !parallelFlags.AtomicLoopStateUpdate ( ParallelLoopStateFlags.ParallelLoopStateBroken, ParallelLoopStateFlags.ParallelLoopStateStopped | ParallelLoopStateFlags.ParallelLoopStateExceptional | ParallelLoopStateFlags.ParallelLoopStateCanceled, out var oldValue ) ) { // If we were already stopped, we have a problem if ((oldValue & ParallelLoopStateFlags.ParallelLoopStateStopped) != 0) { throw new InvalidOperationException ( "SR.ParallelState_Break_InvalidOperationException_BreakAfterStop" ); } // Apparently we previously got cancelled or became exceptional. No action necessary return; } // replace shared LowestBreakIteration with CurrentIteration, but only if CurrentIteration // is less than LowestBreakIteration. var lowestBreakIteration = parallelFlags._lowestBreakIteration; if (iteration >= lowestBreakIteration) { return; } var wait = new SpinWait(); while (Interlocked.CompareExchange(ref parallelFlags._lowestBreakIteration, iteration, lowestBreakIteration) != lowestBreakIteration) { wait.SpinOnce(); lowestBreakIteration = parallelFlags._lowestBreakIteration; if (iteration > lowestBreakIteration) { break; } } }
// Helper method to avoid repeating Break() logic between ParallelState32 and ParallelState32<TLocal> internal static void Break(int iteration, ParallelLoopStateFlags32 pflags) { int oldValue = ParallelLoopStateFlags.PLS_NONE; // Attempt to change state from "not stopped or broken or canceled or exceptional" to "broken". if (!pflags.AtomicLoopStateUpdate(ParallelLoopStateFlags.PLS_BROKEN, ParallelLoopStateFlags.PLS_STOPPED | ParallelLoopStateFlags.PLS_EXCEPTIONAL | ParallelLoopStateFlags.PLS_CANCELED, ref oldValue)) { // If we were already stopped, we have a problem if ((oldValue & ParallelLoopStateFlags.PLS_STOPPED) != 0) { throw new InvalidOperationException( Environment.GetResourceString("ParallelState_Break_InvalidOperationException_BreakAfterStop")); } else { // Apparently we previously got cancelled or became exceptional. No action necessary return; } } // replace shared LowestBreakIteration with CurrentIteration, but only if CurrentIteration // is less than LowestBreakIteration. int oldLBI = pflags.m_lowestBreakIteration; if (iteration < oldLBI) { SpinWait wait = new SpinWait(); while (Interlocked.CompareExchange( ref pflags.m_lowestBreakIteration, iteration, oldLBI) != oldLBI) { wait.SpinOnce(); oldLBI = pflags.m_lowestBreakIteration; if (iteration > oldLBI) { break; } } } }
// Helper method to avoid repeating Break() logic between ParallelState32 and ParallelState32<TLocal> internal static void Break(int iteration, ParallelLoopStateFlags32 pflags) { int oldValue = ParallelLoopStateFlags.ParallelLoopStateNone; // Attempt to change state from "not stopped or broken or canceled or exceptional" to "broken". if (!pflags.AtomicLoopStateUpdate(ParallelLoopStateFlags.ParallelLoopStateBroken, ParallelLoopStateFlags.ParallelLoopStateStopped | ParallelLoopStateFlags.ParallelLoopStateExceptional | ParallelLoopStateFlags.ParallelLoopStateCanceled, ref oldValue)) { // If we were already stopped, we have a problem if ((oldValue & ParallelLoopStateFlags.ParallelLoopStateStopped) != 0) { throw new InvalidOperationException( SR.ParallelState_Break_InvalidOperationException_BreakAfterStop); } else { // Apparently we previously got cancelled or became exceptional. No action necessary return; } } // replace shared LowestBreakIteration with CurrentIteration, but only if CurrentIteration // is less than LowestBreakIteration. int oldLBI = pflags._lowestBreakIteration; if (iteration < oldLBI) { SpinWait wait = default; while (Interlocked.CompareExchange( ref pflags._lowestBreakIteration, iteration, oldLBI) != oldLBI) { wait.SpinOnce(); oldLBI = pflags._lowestBreakIteration; if (iteration > oldLBI) { break; } } } }
/// <summary> /// Internal constructor to ensure an instance isn't created by users. /// </summary> /// <param name="sharedParallelStateFlags">A flag shared among all threads participating /// in the execution of a certain loop.</param> internal ParallelLoopState32(ParallelLoopStateFlags32 sharedParallelStateFlags) : base(sharedParallelStateFlags) { m_sharedParallelStateFlags = sharedParallelStateFlags; }
// Helper method to avoid repeating Break() logic between ParallelState32 and ParallelState32<TLocal> internal static void Break(int iteration, ParallelLoopStateFlags32 pflags) { int oldValue = ParallelLoopStateFlags.PLS_NONE; // Attempt to change state from "not stopped or broken or canceled or exceptional" to "broken". if (!pflags.AtomicLoopStateUpdate(ParallelLoopStateFlags.PLS_BROKEN, ParallelLoopStateFlags.PLS_STOPPED | ParallelLoopStateFlags.PLS_EXCEPTIONAL | ParallelLoopStateFlags.PLS_CANCELED, ref oldValue)) { // If we were already stopped, we have a problem if ((oldValue & ParallelLoopStateFlags.PLS_STOPPED) != 0) { throw new InvalidOperationException( Environment.GetResourceString("ParallelState_Break_InvalidOperationException_BreakAfterStop")); } else { // Apparently we previously got cancelled or became exceptional. No action necessary return; } } // replace shared LowestBreakIteration with CurrentIteration, but only if CurrentIteration // is less than LowestBreakIteration. int oldLBI = pflags.m_lowestBreakIteration; if (iteration < oldLBI) { SpinWait wait = new SpinWait(); while (Interlocked.CompareExchange( ref pflags.m_lowestBreakIteration, iteration, oldLBI) != oldLBI) { wait.SpinOnce(); oldLBI = pflags.m_lowestBreakIteration; if (iteration > oldLBI) break; } } }
// Helper method to avoid repeating Break() logic between ParallelState32 and ParallelState32<TLocal> internal static void Break(int iteration, ParallelLoopStateFlags32 pflags) { int oldValue = ParallelLoopStateFlags.ParallelLoopStateNone; // Attempt to change state from "not stopped or broken or canceled or exceptional" to "broken". if (!pflags.AtomicLoopStateUpdate(ParallelLoopStateFlags.ParallelLoopStateBroken, ParallelLoopStateFlags.ParallelLoopStateStopped | ParallelLoopStateFlags.ParallelLoopStateExceptional | ParallelLoopStateFlags.ParallelLoopStateCanceled, ref oldValue)) { // If we were already stopped, we have a problem if ((oldValue & ParallelLoopStateFlags.ParallelLoopStateStopped) != 0) { throw new InvalidOperationException( SR.ParallelState_Break_InvalidOperationException_BreakAfterStop); } else { // Apparently we previously got cancelled or became exceptional. No action necessary return; } } // replace shared LowestBreakIteration with CurrentIteration, but only if CurrentIteration // is less than LowestBreakIteration. int oldLBI = pflags._lowestBreakIteration; if (iteration < oldLBI) { SpinWait wait = new SpinWait(); while (Interlocked.CompareExchange( ref pflags._lowestBreakIteration, iteration, oldLBI) != oldLBI) { wait.SpinOnce(); oldLBI = pflags._lowestBreakIteration; if (iteration > oldLBI) break; } } }