Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
LowLevelSpinWaiter.cs
Go to the documentation of this file.
1namespace System.Threading;
2
3internal struct LowLevelSpinWaiter
4{
6
7 public bool SpinWaitForCondition(Func<bool> condition, int spinCount, int sleep0Threshold)
8 {
9 int processorCount = Environment.ProcessorCount;
11 try
12 {
13 if (num <= processorCount)
14 {
15 for (int i = ((processorCount <= 1) ? sleep0Threshold : 0); i < spinCount; i++)
16 {
17 Wait(i, sleep0Threshold, processorCount);
18 if (condition())
19 {
20 return true;
21 }
22 }
23 }
24 }
25 finally
26 {
28 }
29 return false;
30 }
31
32 public static void Wait(int spinIndex, int sleep0Threshold, int processorCount)
33 {
34 if (processorCount > 1 && (spinIndex < sleep0Threshold || (spinIndex - sleep0Threshold) % 2 != 0))
35 {
37 if (spinIndex <= 30 && 1 << spinIndex < num)
38 {
39 num = 1 << spinIndex;
40 }
41 Thread.SpinWait(num);
42 }
43 else
44 {
46 }
47 }
48}
static int ProcessorCount
static int Decrement(ref int location)
static int Increment(ref int location)
static int OptimalMaxSpinWaitsPerSpinIteration
Definition Thread.cs:237
static void SpinWait(int iterations)
Definition Thread.cs:404
static void UninterruptibleSleep0()
bool SpinWaitForCondition(Func< bool > condition, int spinCount, int sleep0Threshold)
static void Wait(int spinIndex, int sleep0Threshold, int processorCount)