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

◆ AdjustMaxWorkersActive()

void System.Threading.PortableThreadPool.AdjustMaxWorkersActive ( )
inlineprivate

Definition at line 1521 of file PortableThreadPool.cs.

1522 {
1523 LowLevelLock threadAdjustmentLock = _threadAdjustmentLock;
1524 if (!threadAdjustmentLock.TryAcquire())
1525 {
1526 return;
1527 }
1528 bool flag = false;
1529 try
1530 {
1531 ThreadCounts counts = _separated.counts;
1532 if (counts.NumProcessingWork > counts.NumThreadsGoal || _pendingBlockingAdjustment != 0)
1533 {
1534 return;
1535 }
1536 long currentSampleStartTime = _currentSampleStartTime;
1537 long timestamp = Stopwatch.GetTimestamp();
1538 long frequency = Stopwatch.Frequency;
1539 double num = (double)(timestamp - currentSampleStartTime) / (double)frequency;
1540 if (num * 1000.0 >= (double)(_threadAdjustmentIntervalMs / 2))
1541 {
1542 int tickCount = Environment.TickCount;
1543 int num2 = (int)_completionCounter.Count;
1544 int numCompletions = num2 - _separated.priorCompletionCount;
1545 short numThreadsGoal = counts.NumThreadsGoal;
1546 int num3;
1547 (num3, _threadAdjustmentIntervalMs) = HillClimbing.ThreadPoolHillClimber.Update(numThreadsGoal, num, numCompletions);
1548 if (numThreadsGoal != (short)num3)
1549 {
1551 if (num3 > numThreadsGoal)
1552 {
1553 flag = true;
1554 }
1555 }
1556 _separated.priorCompletionCount = num2;
1557 _separated.nextCompletedWorkRequestsTime = tickCount + _threadAdjustmentIntervalMs;
1559 _currentSampleStartTime = timestamp;
1560 }
1561 }
1562 finally
1563 {
1564 threadAdjustmentLock.Release();
1565 }
1566 if (flag)
1567 {
1568 WorkerThread.MaybeAddWorkingWorker(this);
1569 }
1570 }
static readonly long Frequency
Definition Stopwatch.cs:13
PendingBlockingAdjustment _pendingBlockingAdjustment
readonly ThreadInt64PersistentCounter _completionCounter

References System.Threading.PortableThreadPool._completionCounter, System.Threading.PortableThreadPool._currentSampleStartTime, System.Threading.PortableThreadPool._pendingBlockingAdjustment, System.Threading.PortableThreadPool._separated, System.Threading.PortableThreadPool._threadAdjustmentIntervalMs, System.Threading.PortableThreadPool._threadAdjustmentLock, System.Threading.ThreadInt64PersistentCounter.Count, System.Threading.PortableThreadPool.CacheLineSeparated.counts, System.Diagnostics.Stopwatch.Frequency, System.Diagnostics.Stopwatch.GetTimestamp(), System.Threading.PortableThreadPool.ThreadCounts.InterlockedSetNumThreadsGoal(), System.Threading.PortableThreadPool.WorkerThread.MaybeAddWorkingWorker(), System.Threading.PortableThreadPool.ThreadCounts.NumProcessingWork, System.Threading.PortableThreadPool.ThreadCounts.NumThreadsGoal, System.Threading.PortableThreadPool.CacheLineSeparated.priorCompletedWorkRequestsTime, System.Threading.PortableThreadPool.CacheLineSeparated.priorCompletionCount, System.Threading.LowLevelLock.Release(), System.Threading.PortableThreadPool.HillClimbing.ThreadPoolHillClimber, System.Environment.TickCount, System.Threading.LowLevelLock.TryAcquire(), and System.Threading.Volatile.Write().

Referenced by System.Threading.PortableThreadPool.NotifyWorkItemProgress().