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

◆ WorkerThreadStart()

static void System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart ( )
inlinestaticprivate

Definition at line 1005 of file PortableThreadPool.cs.

1006 {
1007 Thread.CurrentThread.SetThreadPoolWorkerThreadName();
1008 PortableThreadPool threadPoolInstance = ThreadPoolInstance;
1009 if (NativeRuntimeEventSource.Log.IsEnabled())
1010 {
1011 NativeRuntimeEventSource.Log.ThreadPoolWorkerThreadStart((uint)threadPoolInstance._separated.counts.VolatileRead().NumExistingThreads, 0u, 0);
1012 }
1013 LowLevelLock threadAdjustmentLock = threadPoolInstance._threadAdjustmentLock;
1014 LowLevelLifoSemaphore lowLevelLifoSemaphore = s_semaphore;
1015 while (true)
1016 {
1017 bool spinWait = true;
1018 while (lowLevelLifoSemaphore.Wait(20000, spinWait))
1019 {
1020 bool flag = false;
1021 while (TakeActiveRequest(threadPoolInstance))
1022 {
1023 threadPoolInstance._separated.lastDequeueTime = Environment.TickCount;
1024 if (!ThreadPoolWorkQueue.Dispatch())
1025 {
1026 flag = true;
1027 break;
1028 }
1029 if (threadPoolInstance._separated.numRequestedWorkers <= 0)
1030 {
1031 break;
1032 }
1033 Thread.UninterruptibleSleep0();
1034 if (!Environment.IsSingleProcessor)
1035 {
1036 Thread.SpinWait(1);
1037 }
1038 }
1039 spinWait = !flag;
1040 if (!flag)
1041 {
1042 RemoveWorkingWorker(threadPoolInstance);
1043 }
1044 }
1045 threadAdjustmentLock.Acquire();
1046 try
1047 {
1048 ThreadCounts threadCounts = threadPoolInstance._separated.counts;
1049 while (true)
1050 {
1051 short numExistingThreads = threadCounts.NumExistingThreads;
1052 if (numExistingThreads <= threadCounts.NumProcessingWork)
1053 {
1054 break;
1055 }
1056 ThreadCounts newCounts = threadCounts;
1057 newCounts.SubtractNumExistingThreads(1);
1058 short num = (short)(numExistingThreads - 1);
1059 short newThreadCount = (newCounts.NumThreadsGoal = Math.Max(threadPoolInstance.MinThreadsGoal, Math.Min(num, threadCounts.NumThreadsGoal)));
1060 ThreadCounts threadCounts2 = threadPoolInstance._separated.counts.InterlockedCompareExchange(newCounts, threadCounts);
1061 if (threadCounts2 == threadCounts)
1062 {
1063 HillClimbing.ThreadPoolHillClimber.ForceChange(newThreadCount, HillClimbing.StateOrTransition.ThreadTimedOut);
1064 if (NativeRuntimeEventSource.Log.IsEnabled())
1065 {
1066 NativeRuntimeEventSource.Log.ThreadPoolWorkerThreadStop((uint)num, 0u, 0);
1067 }
1068 return;
1069 }
1070 threadCounts = threadCounts2;
1071 }
1072 }
1073 finally
1074 {
1075 threadAdjustmentLock.Release();
1076 }
1077 }
1078 }
static void RemoveWorkingWorker(PortableThreadPool threadPoolInstance)
static readonly LowLevelLifoSemaphore s_semaphore
static bool TakeActiveRequest(PortableThreadPool threadPoolInstance)
static readonly PortableThreadPool ThreadPoolInstance

References System.Threading.PortableThreadPool._separated, System.Threading.PortableThreadPool._threadAdjustmentLock, System.Threading.LowLevelLock.Acquire(), System.Threading.PortableThreadPool.CacheLineSeparated.counts, System.Threading.Thread.CurrentThread, System.Threading.ThreadPoolWorkQueue.Dispatch(), System.Threading.PortableThreadPool.ThreadCounts.InterlockedCompareExchange(), System.Environment.IsSingleProcessor, System.Diagnostics.Tracing.NativeRuntimeEventSource.Log, System.Math.Max(), System.Math.Min(), System.Threading.PortableThreadPool.MinThreadsGoal, System.Threading.PortableThreadPool.ThreadCounts.NumExistingThreads, System.Threading.PortableThreadPool.ThreadCounts.NumProcessingWork, System.Threading.PortableThreadPool.CacheLineSeparated.numRequestedWorkers, System.Threading.PortableThreadPool.ThreadCounts.NumThreadsGoal, System.Threading.LowLevelLock.Release(), System.Threading.PortableThreadPool.WorkerThread.RemoveWorkingWorker(), System.Threading.PortableThreadPool.WorkerThread.s_semaphore, System.Threading.Thread.SpinWait(), System.Threading.PortableThreadPool.ThreadCounts.SubtractNumExistingThreads(), System.Threading.PortableThreadPool.WorkerThread.TakeActiveRequest(), System.Threading.PortableThreadPool.HillClimbing.ThreadPoolHillClimber, System.Threading.PortableThreadPool.ThreadPoolInstance, System.Environment.TickCount, System.Threading.Thread.UninterruptibleSleep0(), System.Threading.PortableThreadPool.ThreadCounts.VolatileRead(), and System.Threading.LowLevelLifoSemaphore.Wait().