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

◆ TryPopCore() [2/2]

int System.Collections.Concurrent.ConcurrentStack< T >.TryPopCore ( int count,
out Node poppedHead )
inlineprivate

Definition at line 246 of file ConcurrentStack.cs.

247 {
248 SpinWait spinWait = default(SpinWait);
249 int num = 1;
250 Node head;
251 int i;
252 while (true)
253 {
254 head = _head;
255 if (head == null)
256 {
257 if (count == 1 && CDSCollectionETWBCLProvider.Log.IsEnabled())
258 {
259 CDSCollectionETWBCLProvider.Log.ConcurrentStack_FastPopFailed(spinWait.Count);
260 }
261 poppedHead = null;
262 return 0;
263 }
264 Node node = head;
265 for (i = 1; i < count; i++)
266 {
267 if (node._next == null)
268 {
269 break;
270 }
271 node = node._next;
272 }
273 if (Interlocked.CompareExchange(ref _head, node._next, head) == head)
274 {
275 break;
276 }
277 for (int j = 0; j < num; j++)
278 {
279 spinWait.SpinOnce(-1);
280 }
281 num = ((!spinWait.NextSpinWillYield) ? (num * 2) : Random.Shared.Next(1, 8));
282 }
283 if (count == 1 && CDSCollectionETWBCLProvider.Log.IsEnabled())
284 {
285 CDSCollectionETWBCLProvider.Log.ConcurrentStack_FastPopFailed(spinWait.Count);
286 }
287 poppedHead = head;
288 return i;
289 }
static int CompareExchange(ref int location1, int value, int comparand)

References System.Collections.Concurrent.ConcurrentStack< T >._head, System.Threading.Interlocked.CompareExchange(), System.count, System.Collections.Generic.Dictionary< TKey, TValue >.Count, System.Collections.Concurrent.CDSCollectionETWBCLProvider.Log, and System.Random.Shared.