6[DebuggerDisplay(
"Participant Count={ParticipantCount},Participants Remaining={ParticipantsRemaining}")]
34 int num = currentTotalCount & 0x7FFF;
35 int num2 = (currentTotalCount & 0x7FFF0000) >> 16;
55 : this(participantCount, null)
59 public Barrier(
int participantCount, Action<Barrier>? postPhaseAction)
61 if (participantCount < 0 || participantCount > 32767)
69 if (postPhaseAction !=
null)
76 private void GetCurrentTotal(
int currentTotal, out
int current, out
int total, out
bool sense)
78 total = currentTotal & 0x7FFF;
79 current = (currentTotal & 0x7FFF0000) >> 16;
80 sense = (currentTotal &
int.MinValue) == 0;
83 private bool SetCurrentTotal(
int currentTotal,
int current,
int total,
bool sense)
85 int num = (current << 16) | total;
93 [UnsupportedOSPlatform(
"browser")]
106 [UnsupportedOSPlatform(
"browser")]
110 if (participantCount < 1)
114 if (participantCount > 32767)
128 GetCurrentTotal(currentTotalCount, out var current, out var total, out sense);
129 if (participantCount + total > 32767)
133 if (
SetCurrentTotal(currentTotalCount, current, total + participantCount, sense))
140 num = ((sense != (currentPhaseNumber % 2 == 0)) ? (currentPhaseNumber + 1) : currentPhaseNumber);
141 if (num != currentPhaseNumber)
171 if (participantCount < 1)
183 GetCurrentTotal(currentTotalCount, out var current, out var total, out var sense);
184 if (total < participantCount)
188 if (total - participantCount < current)
192 int num = total - participantCount;
193 if (num > 0 && current == num)
195 if (
SetCurrentTotal(currentTotalCount, 0, total - participantCount, !sense))
201 else if (
SetCurrentTotal(currentTotalCount, current, total - participantCount, sense))
209 [UnsupportedOSPlatform(
"browser")]
215 [UnsupportedOSPlatform(
"browser")]
221 [UnsupportedOSPlatform(
"browser")]
227 [UnsupportedOSPlatform(
"browser")]
230 long num = (long)
timeout.TotalMilliseconds;
231 if (num < -1 || num >
int.MaxValue)
238 [UnsupportedOSPlatform(
"browser")]
244 [UnsupportedOSPlatform(
"browser")]
261 long currentPhaseNumber;
275 if (current + 1 == total)
287 else if (
SetCurrentTotal(currentTotalCount, current + 1, total, sense))
318 GetCurrentTotal(currentTotalCount, out current, out total, out var sense2);
409 [UnsupportedOSPlatform(
"browser")]
416 int num3 = ((totalTimeout == -1) ? num :
Math.
Min(num, totalTimeout));
417 if (currentPhaseEvent.
Wait(num3, token))
421 if (totalTimeout != -1)
423 totalTimeout -= num3;
424 if (totalTimeout <= 0)
429 num = ((num >= num2) ? num2 :
Math.
Min(num << 1, num2));
445 protected virtual void Dispose(
bool disposing)
static int CurrentManagedThreadId
static void SuppressFinalize(object obj)
static byte Min(byte val1, byte val2)
static string Barrier_SignalAndWait_InvalidOperation_ThreadsExceeded
static string Barrier_AddParticipants_NonPositive_ArgumentOutOfRange
static string Barrier_AddParticipants_Overflow_ArgumentOutOfRange
static string Barrier_ctor_ArgumentOutOfRange
static string Barrier_InvalidOperation_CalledFromPHA
static string Barrier_RemoveParticipants_NonPositive_ArgumentOutOfRange
static string Barrier_SignalAndWait_ArgumentOutOfRange
static string Barrier_Dispose
static string Barrier_RemoveParticipants_InvalidOperation
static string Barrier_SignalAndWait_InvalidOperation_ZeroTotal
static string Barrier_RemoveParticipants_ArgumentOutOfRange
static string Common_OperationCanceled
void FinishPhase(bool observedSense)
static void InvokePostPhaseAction(object obj)
Barrier(int participantCount)
bool SignalAndWait(TimeSpan timeout, CancellationToken cancellationToken)
void SetResetEvents(bool observedSense)
void GetCurrentTotal(int currentTotal, out int current, out int total, out bool sense)
readonly Action< Barrier > _postPhaseAction
long AddParticipants(int participantCount)
void RemoveParticipants(int participantCount)
static ContextCallback s_invokePostPhaseAction
bool SetCurrentTotal(int currentTotal, int current, int total, bool sense)
virtual void Dispose(bool disposing)
volatile int _currentTotalCount
bool SignalAndWait(int millisecondsTimeout, CancellationToken cancellationToken)
readonly ManualResetEventSlim _oddEvent
readonly ManualResetEventSlim _evenEvent
bool SignalAndWait(TimeSpan timeout)
bool DiscontinuousWait(ManualResetEventSlim currentPhaseEvent, int totalTimeout, CancellationToken token, long observedPhase)
bool SignalAndWait(int millisecondsTimeout)
readonly ExecutionContext _ownerThreadContext
void WaitCurrentPhase(ManualResetEventSlim currentPhaseEvent, long observedPhase)
int ParticipantsRemaining
Barrier(int participantCount, Action< Barrier >? postPhaseAction)
void SignalAndWait(CancellationToken cancellationToken)
static CdsSyncEtwBCLProvider Log
static ? ExecutionContext Capture()
static void Run(ExecutionContext executionContext, ContextCallback callback, object? state)
static int CompareExchange(ref int location1, int value, int comparand)
static bool Read(ref bool location)
static void Write(ref bool location, bool value)
delegate void ContextCallback(object? state)
static CancellationToken None