// Token: 0x06003F30 RID: 16176 RVA: 0x000EB7EC File Offset: 0x000E99EC internal static void Break(long iteration, ParallelLoopStateFlags64 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)) { long lowestBreakIteration = pflags.LowestBreakIteration; if (iteration < lowestBreakIteration) { SpinWait spinWait = default(SpinWait); while (Interlocked.CompareExchange(ref pflags.m_lowestBreakIteration, iteration, lowestBreakIteration) != lowestBreakIteration) { spinWait.SpinOnce(); lowestBreakIteration = pflags.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(long iteration, ParallelLoopStateFlags64 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 { long lowestBreakIteration = pflags.LowestBreakIteration; if (iteration < lowestBreakIteration) { SpinWait wait = new SpinWait(); while (Interlocked.CompareExchange(ref pflags.m_lowestBreakIteration, iteration, lowestBreakIteration) != lowestBreakIteration) { wait.SpinOnce(); lowestBreakIteration = pflags.LowestBreakIteration; if (iteration > lowestBreakIteration) { return; } } } } }
// Helper method to avoid repeating Break() logic between ParallelState64 and ParallelState64<TLocal> internal static void Break(long iteration, ParallelLoopStateFlags64 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 ParallelState64 and ParallelState64<TLocal> internal static void Break(long iteration, ParallelLoopStateFlags64 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. long oldLBI = pflags.LowestBreakIteration; if (iteration < oldLBI) { SpinWait wait = new SpinWait(); while (Interlocked.CompareExchange( ref pflags.m_lowestBreakIteration, iteration, oldLBI) != oldLBI) { wait.SpinOnce(); oldLBI = pflags.LowestBreakIteration; if (iteration > oldLBI) { break; } } } }
// Helper method to avoid repeating Break() logic between ParallelState64 and ParallelState64<TLocal> internal static void Break(long iteration, ParallelLoopStateFlags64 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. long 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 ParallelLoopState64(ParallelLoopStateFlags64 sharedParallelStateFlags) : base(sharedParallelStateFlags) { m_sharedParallelStateFlags = sharedParallelStateFlags; }
/// <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 ParallelLoopState64(ParallelLoopStateFlags64 sharedParallelStateFlags) : base(sharedParallelStateFlags) { m_sharedParallelStateFlags = sharedParallelStateFlags; }
// Helper method to avoid repeating Break() logic between ParallelState64 and ParallelState64<TLocal> internal static void Break(long iteration, ParallelLoopStateFlags64 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. long oldLBI = pflags.LowestBreakIteration; if (iteration < oldLBI) { SpinWait wait = new SpinWait(); while (Interlocked.CompareExchange( ref pflags.m_lowestBreakIteration, iteration, oldLBI) != oldLBI) { wait.SpinOnce(); oldLBI = pflags.LowestBreakIteration; if (iteration > oldLBI) break; } } }