Merge pull request #11855 from akallabeth/threadpool

[winpr,threadpool] default minimum thread count
This commit is contained in:
akallabeth
2025-09-12 09:33:45 +02:00
committed by GitHub
3 changed files with 33 additions and 6 deletions

View File

@@ -1455,11 +1455,31 @@ freerdp_peer* freerdp_peer_new(int sockfd)
if (sockfd >= 0)
{
if (setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (void*)&option_value, option_len) < 0)
int type = -1;
socklen_t typelen = sizeof(type);
const int rc = getsockopt(sockfd, SOL_SOCKET, SO_TYPE, &type, &typelen);
if (rc < 0)
{
/* local unix sockets don't have the TCP_NODELAY implemented, so don't make this
* error fatal */
WLog_DBG(TAG, "can't set TCP_NODELAY, continuing anyway");
char buffer[128] = { 0 };
WLog_DBG(TAG, "can't get SOL_SOCKET|SO_TYPE, continuing anyway (%s)",
winpr_strerror(errno, buffer, sizeof(buffer)));
}
else if (type == SOCK_STREAM)
{
const int sr =
setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (void*)&option_value, option_len);
if (sr < 0)
{
/* local unix sockets don't have the TCP_NODELAY implemented, so don't make this
* error fatal */
char buffer[128] = { 0 };
WLog_DBG(TAG, "can't set TCP_NODELAY, continuing anyway (%s)",
winpr_strerror(errno, buffer, sizeof(buffer)));
}
}
else
{
WLog_DBG(TAG, "Socket SOL_SOCKET|SO_TYPE %d unsupported, continuing anyway", type);
}
}

View File

@@ -16,7 +16,9 @@
# limitations under the License.
set(WINPR_THREADPOOL_DEFAULT_MAX_COUNT "16" CACHE STRING "The maximum (default) number of threads in a pool")
set(WINPR_THREADPOOL_DEFAULT_MIN_COUNT "4" CACHE STRING "The minimum (default) number of threads in a pool")
winpr_definition_add(WINPR_THREADPOOL_DEFAULT_MAX_COUNT=${WINPR_THREADPOOL_DEFAULT_MAX_COUNT})
winpr_definition_add(WINPR_THREADPOOL_DEFAULT_MIN_COUNT=${WINPR_THREADPOOL_DEFAULT_MIN_COUNT})
winpr_module_add(
synch.c
work.c

View File

@@ -127,10 +127,15 @@ static BOOL InitializeThreadpool(PTP_POOL pool)
obj = ArrayList_Object(pool->Threads);
obj->fnObjectFree = threads_close;
#if !defined(WINPR_THREADPOOL_DEFAULT_MIN_COUNT)
#error "WINPR_THREADPOOL_DEFAULT_MIN_COUNT must be defined"
#endif
SYSTEM_INFO info = { 0 };
GetSystemInfo(&info);
if (info.dwNumberOfProcessors < 1)
info.dwNumberOfProcessors = 1;
if (info.dwNumberOfProcessors < WINPR_THREADPOOL_DEFAULT_MIN_COUNT)
info.dwNumberOfProcessors = WINPR_THREADPOOL_DEFAULT_MIN_COUNT;
if (!SetThreadpoolThreadMinimum(pool, info.dwNumberOfProcessors))
goto fail;