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

◆ MaybeAddWorkingWorker()

static void System.Threading.PortableThreadPool.WorkerThread.MaybeAddWorkingWorker ( PortableThreadPool threadPoolInstance)
inlinestaticpackage

Definition at line 1089 of file PortableThreadPool.cs.

1090 {
1091 ThreadCounts threadCounts = threadPoolInstance._separated.counts;
1092 short numProcessingWork;
1093 short num;
1094 short numExistingThreads;
1095 short num2;
1096 while (true)
1097 {
1098 numProcessingWork = threadCounts.NumProcessingWork;
1099 if (numProcessingWork >= threadCounts.NumThreadsGoal)
1100 {
1101 return;
1102 }
1103 num = (short)(numProcessingWork + 1);
1104 numExistingThreads = threadCounts.NumExistingThreads;
1105 num2 = Math.Max(numExistingThreads, num);
1106 ThreadCounts newCounts = threadCounts;
1107 newCounts.NumProcessingWork = num;
1108 newCounts.NumExistingThreads = num2;
1109 ThreadCounts threadCounts2 = threadPoolInstance._separated.counts.InterlockedCompareExchange(newCounts, threadCounts);
1110 if (threadCounts2 == threadCounts)
1111 {
1112 break;
1113 }
1114 threadCounts = threadCounts2;
1115 }
1116 int num3 = num2 - numExistingThreads;
1117 int num4 = num - numProcessingWork;
1118 if (num4 > 0)
1119 {
1120 s_semaphore.Release(num4);
1121 }
1122 while (num3 > 0)
1123 {
1125 {
1126 num3--;
1127 continue;
1128 }
1129 threadCounts = threadPoolInstance._separated.counts;
1130 while (true)
1131 {
1132 ThreadCounts newCounts2 = threadCounts;
1133 newCounts2.SubtractNumProcessingWork((short)num3);
1134 newCounts2.SubtractNumExistingThreads((short)num3);
1135 ThreadCounts threadCounts3 = threadPoolInstance._separated.counts.InterlockedCompareExchange(newCounts2, threadCounts);
1136 if (!(threadCounts3 == threadCounts))
1137 {
1138 threadCounts = threadCounts3;
1139 continue;
1140 }
1141 break;
1142 }
1143 break;
1144 }
1145 }
static readonly LowLevelLifoSemaphore s_semaphore

References System.Threading.PortableThreadPool._separated, System.Threading.PortableThreadPool.CacheLineSeparated.counts, System.Threading.PortableThreadPool.ThreadCounts.InterlockedCompareExchange(), System.Math.Max(), System.Threading.PortableThreadPool.ThreadCounts.NumExistingThreads, System.Threading.PortableThreadPool.ThreadCounts.NumProcessingWork, System.Threading.PortableThreadPool.ThreadCounts.NumThreadsGoal, System.Threading.PortableThreadPool.WorkerThread.s_semaphore, System.Threading.PortableThreadPool.ThreadCounts.SubtractNumExistingThreads(), System.Threading.PortableThreadPool.ThreadCounts.SubtractNumProcessingWork(), and System.Threading.PortableThreadPool.WorkerThread.TryCreateWorkerThread().

Referenced by System.Threading.PortableThreadPool.AdjustMaxWorkersActive(), System.Threading.PortableThreadPool.GateThread.GateThreadStart(), System.Threading.PortableThreadPool.PerformBlockingAdjustment(), System.Threading.PortableThreadPool.WorkerThread.RemoveWorkingWorker(), System.Threading.PortableThreadPool.RequestWorker(), and System.Threading.PortableThreadPool.SetMinThreads().