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

◆ AddParticipants()

long System.Threading.Barrier.AddParticipants ( int participantCount)
inline

Definition at line 107 of file Barrier.cs.

108 {
110 if (participantCount < 1)
111 {
112 throw new ArgumentOutOfRangeException("participantCount", participantCount, System.SR.Barrier_AddParticipants_NonPositive_ArgumentOutOfRange);
113 }
114 if (participantCount > 32767)
115 {
116 throw new ArgumentOutOfRangeException("participantCount", System.SR.Barrier_AddParticipants_Overflow_ArgumentOutOfRange);
117 }
118 if (_actionCallerID != 0 && Environment.CurrentManagedThreadId == _actionCallerID)
119 {
121 }
122 SpinWait spinWait = default(SpinWait);
123 long num = 0L;
124 bool sense;
125 while (true)
126 {
127 int currentTotalCount = _currentTotalCount;
128 GetCurrentTotal(currentTotalCount, out var current, out var total, out sense);
129 if (participantCount + total > 32767)
130 {
131 throw new ArgumentOutOfRangeException("participantCount", System.SR.Barrier_AddParticipants_Overflow_ArgumentOutOfRange);
132 }
133 if (SetCurrentTotal(currentTotalCount, current, total + participantCount, sense))
134 {
135 break;
136 }
137 spinWait.SpinOnce(-1);
138 }
139 long currentPhaseNumber = CurrentPhaseNumber;
140 num = ((sense != (currentPhaseNumber % 2 == 0)) ? (currentPhaseNumber + 1) : currentPhaseNumber);
141 if (num != currentPhaseNumber)
142 {
143 if (sense)
144 {
145 _oddEvent.Wait();
146 }
147 else
148 {
150 }
151 }
152 else if (sense && _evenEvent.IsSet)
153 {
155 }
156 else if (!sense && _oddEvent.IsSet)
157 {
159 }
160 return num;
161 }
static string Barrier_AddParticipants_NonPositive_ArgumentOutOfRange
Definition SR.cs:36
static string Barrier_AddParticipants_Overflow_ArgumentOutOfRange
Definition SR.cs:44
static string Barrier_InvalidOperation_CalledFromPHA
Definition SR.cs:34
Definition SR.cs:7
void GetCurrentTotal(int currentTotal, out int current, out int total, out bool sense)
Definition Barrier.cs:76
bool SetCurrentTotal(int currentTotal, int current, int total, bool sense)
Definition Barrier.cs:83
volatile int _currentTotalCount
Definition Barrier.cs:9
readonly ManualResetEventSlim _oddEvent
Definition Barrier.cs:15
readonly ManualResetEventSlim _evenEvent
Definition Barrier.cs:17

References System.Threading.Barrier._actionCallerID, System.Threading.Barrier._currentTotalCount, System.Threading.Barrier._evenEvent, System.Threading.Barrier._oddEvent, System.SR.Barrier_AddParticipants_NonPositive_ArgumentOutOfRange, System.SR.Barrier_AddParticipants_Overflow_ArgumentOutOfRange, System.SR.Barrier_InvalidOperation_CalledFromPHA, System.Environment.CurrentManagedThreadId, System.Threading.Barrier.CurrentPhaseNumber, System.Threading.Barrier.GetCurrentTotal(), System.Threading.ManualResetEventSlim.IsSet, System.L, System.Threading.ManualResetEventSlim.Reset(), System.Threading.Barrier.SetCurrentTotal(), System.Threading.SpinWait.SpinOnce(), System.Threading.Barrier.ThrowIfDisposed(), and System.Threading.ManualResetEventSlim.Wait().

Referenced by System.Threading.Barrier.AddParticipant().