From: Paul Cruz Date: Fri, 21 Jul 2017 16:30:24 +0000 (-0700) Subject: added bounding to compression level change X-Git-Tag: v1.3.1^2~13^2^2~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=721c6a8b973c8a2e23a4f4eec56bf77e253098ea;p=thirdparty%2Fzstd.git added bounding to compression level change --- diff --git a/contrib/adaptive-compression/adapt.c b/contrib/adaptive-compression/adapt.c index 758bf5589..c542c9a3d 100644 --- a/contrib/adaptive-compression/adapt.c +++ b/contrib/adaptive-compression/adapt.c @@ -323,20 +323,23 @@ static void adaptCompressionLevel(adaptCCtx* ctx) if (1 - createCompletion > threshold) { /* job creation was not finished, compression thread waited */ unsigned const change = MAX_COMPRESSION_LEVEL_CHANGE - createCompletion * MAX_COMPRESSION_LEVEL_CHANGE; + unsigned const boundChange = MIN(change, ZSTD_maxCLevel() - ctx->compressionLevel); DEBUG(2, "increasing compression level %u by %u\n", ctx->compressionLevel, change); - ctx->compressionLevel += change; + ctx->compressionLevel += boundChange; } else if (1 - writeCompletion > threshold) { /* write thread was not finished, compression thread waited */ unsigned const change = MAX_COMPRESSION_LEVEL_CHANGE - writeCompletion * MAX_COMPRESSION_LEVEL_CHANGE; + unsigned const boundChange = MIN(change, ZSTD_maxCLevel() - ctx->compressionLevel); DEBUG(2, "increasing compression level %u by %u\n", ctx->compressionLevel, change); - ctx->compressionLevel += change; + ctx->compressionLevel += boundChange; } else if (1 - compressionCompletion > threshold) { /* compression thread was not finished, one of the other two threads waited */ unsigned const change = MAX_COMPRESSION_LEVEL_CHANGE - compressionCompletion * MAX_COMPRESSION_LEVEL_CHANGE; + unsigned const boundChange = MIN(change, ctx->compressionLevel - 1); DEBUG(2, "decreasing compression level %u by %u\n", ctx->compressionLevel, change); - ctx->compressionLevel -= change; + ctx->compressionLevel -= boundChange; } /* reset */ pthread_mutex_lock(&ctx->completion_mutex.pMutex);