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

◆ TrySteal()

object System.Threading.ThreadPoolWorkQueue.WorkStealingQueue.TrySteal ( ref bool missedSteal)
inline

Definition at line 271 of file ThreadPoolWorkQueue.cs.

272 {
273 while (CanSteal)
274 {
275 bool lockTaken = false;
276 try
277 {
278 m_foreignLock.TryEnter(ref lockTaken);
279 if (lockTaken)
280 {
281 int headIndex = m_headIndex;
282 Interlocked.Exchange(ref m_headIndex, headIndex + 1);
283 if (headIndex < m_tailIndex)
284 {
285 int num = headIndex & m_mask;
286 object obj = Volatile.Read(ref m_array[num]);
287 if (obj == null)
288 {
289 continue;
290 }
291 m_array[num] = null;
292 return obj;
293 }
294 m_headIndex = headIndex;
295 }
296 }
297 finally
298 {
299 if (lockTaken)
300 {
301 m_foreignLock.Exit(useMemoryBarrier: false);
302 }
303 }
304 missedSteal = true;
305 break;
306 }
307 return null;
308 }
void TryEnter(ref bool lockTaken)
Definition SpinLock.cs:103

References System.Threading.ThreadPoolWorkQueue.WorkStealingQueue.CanSteal, System.Threading.Interlocked.Exchange(), System.Threading.SpinLock.Exit(), System.Threading.ThreadPoolWorkQueue.WorkStealingQueue.m_array, System.Threading.ThreadPoolWorkQueue.WorkStealingQueue.m_foreignLock, System.Threading.ThreadPoolWorkQueue.WorkStealingQueue.m_headIndex, System.Threading.ThreadPoolWorkQueue.WorkStealingQueue.m_mask, System.Threading.ThreadPoolWorkQueue.WorkStealingQueue.m_tailIndex, System.obj, System.Threading.Volatile.Read(), and System.Threading.SpinLock.TryEnter().

Referenced by System.Threading.ThreadPoolWorkQueue.Dequeue().