[winpr,pool] limit threadpool to 16 threads by default

Initialize the threadpool to minimum of number of processors and 16 by
default.
This commit is contained in:
Armin Novak
2025-09-03 14:03:10 +02:00
parent 934a4866ec
commit c2fc455d8f
2 changed files with 11 additions and 4 deletions

View File

@@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
set(WINPR_THREADPOOL_DEFAULT_MAX_COUNT "16" CACHE STRING "The maximum (default) number of threads in a pool")
winpr_definition_add(WINPR_THREADPOOL_DEFAULT_MAX_COUNT=${WINPR_THREADPOOL_DEFAULT_MAX_COUNT})
winpr_module_add(
synch.c
work.c

View File

@@ -133,7 +133,14 @@ static BOOL InitializeThreadpool(PTP_POOL pool)
info.dwNumberOfProcessors = 1;
if (!SetThreadpoolThreadMinimum(pool, info.dwNumberOfProcessors))
goto fail;
SetThreadpoolThreadMaximum(pool, info.dwNumberOfProcessors);
#if !defined(WINPR_THREADPOOL_DEFAULT_MAX_COUNT)
#error "WINPR_THREADPOOL_DEFAULT_MAX_COUNT must be defined"
#endif
DWORD max = info.dwNumberOfProcessors;
if (max > WINPR_THREADPOOL_DEFAULT_MAX_COUNT)
max = WINPR_THREADPOOL_DEFAULT_MAX_COUNT;
SetThreadpoolThreadMaximum(pool, max);
rc = TRUE;
@@ -143,9 +150,7 @@ fail:
PTP_POOL GetDefaultThreadpool(void)
{
PTP_POOL pool = NULL;
pool = &DEFAULT_POOL;
PTP_POOL pool = &DEFAULT_POOL;
if (!InitializeThreadpool(pool))
return NULL;