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

◆ TrySteal()

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

Definition at line 206 of file ConcurrentBag.cs.

207 {
208 lock (this)
209 {
210 int headIndex = _headIndex;
211 if (take)
212 {
213 if (headIndex - (_tailIndex - 2) >= 0 && _currentOp == 1)
214 {
215 SpinWait spinWait = default(SpinWait);
216 do
217 {
218 spinWait.SpinOnce();
219 }
220 while (_currentOp == 1);
221 }
223 if (headIndex < _tailIndex)
224 {
225 int num = headIndex & _mask;
226 result = _array[num];
227 if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
228 {
229 _array[num] = default(T);
230 }
231 _stealCount++;
232 return true;
233 }
235 }
236 else if (headIndex < _tailIndex)
237 {
238 result = _array[headIndex & _mask];
239 return true;
240 }
241 }
242 result = default(T);
243 return false;
244 }
static int Exchange(ref int location1, int value)

References System.Collections.Concurrent.ConcurrentBag< T >.WorkStealingQueue._array, System.Collections.Concurrent.ConcurrentBag< T >.WorkStealingQueue._currentOp, System.Collections.Concurrent.ConcurrentBag< T >.WorkStealingQueue._headIndex, System.Collections.Concurrent.ConcurrentBag< T >.WorkStealingQueue._mask, System.Collections.Concurrent.ConcurrentBag< T >.WorkStealingQueue._stealCount, System.Collections.Concurrent.ConcurrentBag< T >.WorkStealingQueue._tailIndex, and System.Threading.Interlocked.Exchange().