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

◆ TryLocalPop()

bool System.Collections.Concurrent.ConcurrentBag< T >.WorkStealingQueue.TryLocalPop ( [MaybeNullWhen(false)] out T result)
inlinepackage

Definition at line 137 of file ConcurrentBag.cs.

138 {
139 int tailIndex = _tailIndex;
140 if (_headIndex - tailIndex >= 0)
141 {
142 result = default(T);
143 return false;
144 }
145 bool lockTaken = false;
146 try
147 {
148 _currentOp = 2;
150 if (!_frozen && _headIndex - tailIndex < 0)
151 {
152 int num = tailIndex & _mask;
153 result = _array[num];
154 if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
155 {
156 _array[num] = default(T);
157 }
159 return true;
160 }
161 _currentOp = 0;
162 Monitor.Enter(this, ref lockTaken);
163 if (_headIndex - tailIndex <= 0)
164 {
165 int num2 = tailIndex & _mask;
166 result = _array[num2];
167 if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
168 {
169 _array[num2] = default(T);
170 }
172 return true;
173 }
174 _tailIndex = tailIndex + 1;
175 result = default(T);
176 return false;
177 }
178 finally
179 {
180 _currentOp = 0;
181 if (lockTaken)
182 {
183 Monitor.Exit(this);
184 }
185 }
186 }
static int Exchange(ref int location1, int value)
static void Exit(object obj)
static void Enter(object obj)

References System.Collections.Concurrent.ConcurrentBag< T >.WorkStealingQueue._addTakeCount, System.Collections.Concurrent.ConcurrentBag< T >.WorkStealingQueue._array, System.Collections.Concurrent.ConcurrentBag< T >.WorkStealingQueue._currentOp, System.Collections.Concurrent.ConcurrentBag< T >.WorkStealingQueue._frozen, System.Collections.Concurrent.ConcurrentBag< T >.WorkStealingQueue._headIndex, System.Collections.Concurrent.ConcurrentBag< T >.WorkStealingQueue._mask, System.Collections.Concurrent.ConcurrentBag< T >.WorkStealingQueue._tailIndex, System.Threading.Monitor.Enter(), System.Threading.Interlocked.Exchange(), and System.Threading.Monitor.Exit().