Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ProcessorIdCache.cs
Go to the documentation of this file.
3
4namespace System.Threading;
5
6internal static class ProcessorIdCache
7{
8 [ThreadStatic]
9 private static int t_currentProcessorIdCache;
10
11 private static int s_processorIdRefreshRate;
12
13 private static int RefreshCurrentProcessorId()
14 {
16 if (num < 0)
17 {
19 }
20 t_currentProcessorIdCache = ((num << 16) & 0x7FFFFFFF) | s_processorIdRefreshRate;
21 return num;
22 }
23
24 [MethodImpl(MethodImplOptions.AggressiveInlining)]
25 internal static int GetCurrentProcessorId()
26 {
27 int num = t_currentProcessorIdCache--;
28 if ((num & 0xFFFF) == 0)
29 {
31 }
32 return num >> 16;
33 }
34
35 internal static bool ProcessorNumberSpeedCheck()
36 {
37 double num = double.MaxValue;
38 double num2 = double.MaxValue;
41 {
43 return false;
44 }
45 long num3 = Stopwatch.Frequency / 1000000 + 1;
46 for (int i = 0; i < 10; i++)
47 {
48 int num4 = 8;
49 long timestamp;
50 do
51 {
52 num4 *= 2;
53 timestamp = Stopwatch.GetTimestamp();
54 for (int j = 0; j < num4; j++)
55 {
57 }
58 timestamp = Stopwatch.GetTimestamp() - timestamp;
59 }
60 while (timestamp < num3);
61 num = Math.Min(num, (double)timestamp / (double)num4);
62 num4 /= 4;
63 do
64 {
65 num4 *= 2;
66 timestamp = Stopwatch.GetTimestamp();
67 for (int k = 0; k < num4; k++)
68 {
70 }
71 timestamp = Stopwatch.GetTimestamp() - timestamp;
72 }
73 while (timestamp < num3);
74 num2 = Math.Min(num2, (double)timestamp / (double)num4);
75 }
76 s_processorIdRefreshRate = Math.Min((int)(num * 5.0 / num2), 5000);
77 return s_processorIdRefreshRate <= 5;
78 }
79
80 [MethodImpl(MethodImplOptions.NoInlining)]
81 internal static int UninlinedThreadStatic()
82 {
84 }
85}
static int CurrentManagedThreadId
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static int GetCurrentProcessorNumber()