From 08590d273fd9dbf3383ad0911c07835d9380d0d4 Mon Sep 17 00:00:00 2001 From: Danielle Rozenblit Date: Wed, 11 Dec 2024 14:15:24 -0800 Subject: [PATCH] Set lower bound for nbthreads default to 1 --- programs/zstdcli.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/programs/zstdcli.c b/programs/zstdcli.c index 25c997264a..d5b0e7c5dc 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -20,10 +20,6 @@ # define ZSTDCLI_CLEVEL_MAX 19 /* without using --ultra */ #endif -#ifndef ZSTDCLI_NBTHREADS_DEFAULT -#define ZSTDCLI_NBTHREADS_DEFAULT (UTIL_countLogicalCores() / 4 > 4 ? 4 : UTIL_countLogicalCores() / 4) -#endif - /*-************************************ * Dependencies **************************************/ @@ -762,6 +758,9 @@ static int init_cLevel(void) { #ifdef ZSTD_MULTITHREAD static unsigned default_nbThreads(void) { const char* const env = getenv(ENV_NBTHREADS); + unsigned nbthreads_default = UTIL_countLogicalCores() / 4; + if (nbthreads_default < 1) nbthreads_default = 1; + if (nbthreads_default > 4) nbthreads_default = 4; if (env != NULL) { const char* ptr = env; if ((*ptr>='0') && (*ptr<='9')) {