Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit a285a45

Browse files
committed
Merge branch 'master' into beta
2 parents b138175 + 8e63ef9 commit a285a45

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

docs/api/Titanium.Web.Proxy.ProxyServer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ <h5 class="parameters">Parameters</h5>
12911291
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/new/master/apiSpec/new?filename=Titanium_Web_Proxy_ProxyServer_Dispose.md&amp;value=---%0Auid%3A%20Titanium.Web.Proxy.ProxyServer.Dispose%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A">Improve this Doc</a>
12921292
</span>
12931293
<span class="small pull-right mobile-hide">
1294-
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/ProxyServer.cs/#L890">View Source</a>
1294+
<a href="https://github.com/justcoding121/Titanium-Web-Proxy/blob/master/src/Titanium.Web.Proxy/ProxyServer.cs/#L895">View Source</a>
12951295
</span>
12961296
<a id="Titanium_Web_Proxy_ProxyServer_Dispose_" data-uid="Titanium.Web.Proxy.ProxyServer.Dispose*"></a>
12971297
<h4 id="Titanium_Web_Proxy_ProxyServer_Dispose" data-uid="Titanium.Web.Proxy.ProxyServer.Dispose">Dispose()</h4>

src/Titanium.Web.Proxy/ProxyServer.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -752,20 +752,32 @@ private void onAcceptConnection(IAsyncResult asyn)
752752
endPoint.Listener.BeginAcceptTcpClient(onAcceptConnection, endPoint);
753753
}
754754

755+
private Lazy<int> maxWorkerThreads = new Lazy<int>(() =>
756+
{
757+
int maxWorkerThreads;
758+
ThreadPool.GetMaxThreads(out maxWorkerThreads, out var _);
759+
return maxWorkerThreads;
760+
});
761+
755762
/// <summary>
756763
/// Change the ThreadPool.WorkerThread minThread
757764
/// </summary>
758-
/// <param name="piNbWorkerThreadsToAdd">Number of threads to add</param>
759-
private void setThreadPoolMinThread(int piNbWorkerThreadsToAdd)
765+
/// <param name="workerThreadsToAdd">Number of threads to add</param>
766+
private void setThreadPoolMinThread(int workerThreadsToAdd)
760767
{
761768
if (EnableThreadPoolOptimizing)
762769
{
763770
lock (lockThreadPoolTuning)
764771
{
765-
int iWorkerThreads, iCompletionPortThreads;
766-
ThreadPool.GetMinThreads(out iWorkerThreads, out iCompletionPortThreads);
767-
iWorkerThreads = Math.Max(iWorkerThreads + piNbWorkerThreadsToAdd, Environment.ProcessorCount);
768-
ThreadPool.SetMinThreads(iWorkerThreads, iCompletionPortThreads);
772+
int minWorkerThreads, minCompletionPortThreads;
773+
774+
ThreadPool.GetMinThreads(out minWorkerThreads, out minCompletionPortThreads);
775+
minWorkerThreads = Math.Max(minWorkerThreads + workerThreadsToAdd, Environment.ProcessorCount);
776+
777+
if (minWorkerThreads <= maxWorkerThreads.Value)
778+
{
779+
ThreadPool.SetMinThreads(minWorkerThreads, minCompletionPortThreads);
780+
}
769781
}
770782
}
771783
}

0 commit comments

Comments
 (0)