removed ternary operation, added assert statement, check to make sure initial compression level is within bounds
This commit is contained in:
@@ -414,6 +414,8 @@ static void adaptCompressionLevel(adaptCCtx* ctx)
|
|||||||
pthread_mutex_unlock(&ctx->createCompletion_mutex.pMutex);
|
pthread_mutex_unlock(&ctx->createCompletion_mutex.pMutex);
|
||||||
DEBUG(2, "convergence counter: %u\n", ctx->convergenceCounter);
|
DEBUG(2, "convergence counter: %u\n", ctx->convergenceCounter);
|
||||||
|
|
||||||
|
assert(g_minCLevel <= ctx->compressionLevel && g_maxCLevel >= ctx->compressionLevel);
|
||||||
|
|
||||||
/* adaptation logic */
|
/* adaptation logic */
|
||||||
if (ctx->cooldown) ctx->cooldown--;
|
if (ctx->cooldown) ctx->cooldown--;
|
||||||
|
|
||||||
@@ -422,7 +424,7 @@ static void adaptCompressionLevel(adaptCCtx* ctx)
|
|||||||
/* use whichever one waited less because it was slower */
|
/* use whichever one waited less because it was slower */
|
||||||
double const completion = MAX(createWaitCompressionCompletion, writeWaitCompressionCompletion);
|
double const completion = MAX(createWaitCompressionCompletion, writeWaitCompressionCompletion);
|
||||||
unsigned const change = convertCompletionToChange(completion);
|
unsigned const change = convertCompletionToChange(completion);
|
||||||
unsigned const boundChange = ctx->compressionLevel >= g_minCLevel ? MIN(change, ctx->compressionLevel - g_minCLevel) : 0;
|
unsigned const boundChange = MIN(change, ctx->compressionLevel - g_minCLevel);
|
||||||
if (ctx->convergenceCounter >= CONVERGENCE_LOWER_BOUND && boundChange != 0) {
|
if (ctx->convergenceCounter >= CONVERGENCE_LOWER_BOUND && boundChange != 0) {
|
||||||
/* reset convergence counter, might have been a spike */
|
/* reset convergence counter, might have been a spike */
|
||||||
ctx->convergenceCounter = 0;
|
ctx->convergenceCounter = 0;
|
||||||
@@ -440,7 +442,7 @@ static void adaptCompressionLevel(adaptCCtx* ctx)
|
|||||||
/* compress waiting on write */
|
/* compress waiting on write */
|
||||||
double const completion = MIN(compressWaitWriteCompletion, compressWaitCreateCompletion);
|
double const completion = MIN(compressWaitWriteCompletion, compressWaitCreateCompletion);
|
||||||
unsigned const change = convertCompletionToChange(completion);
|
unsigned const change = convertCompletionToChange(completion);
|
||||||
unsigned const boundChange = g_maxCLevel >= ctx->compressionLevel ? MIN(change, g_maxCLevel - ctx->compressionLevel) : 0;
|
unsigned const boundChange = MIN(change, g_maxCLevel - ctx->compressionLevel);
|
||||||
if (ctx->convergenceCounter >= CONVERGENCE_LOWER_BOUND && boundChange != 0) {
|
if (ctx->convergenceCounter >= CONVERGENCE_LOWER_BOUND && boundChange != 0) {
|
||||||
/* reset convergence counter, might have been a spike */
|
/* reset convergence counter, might have been a spike */
|
||||||
ctx->convergenceCounter = 0;
|
ctx->convergenceCounter = 0;
|
||||||
@@ -1000,6 +1002,7 @@ int main(int argCount, const char* argv[])
|
|||||||
const char** filenameTable = (const char**)malloc(argCount*sizeof(const char*));
|
const char** filenameTable = (const char**)malloc(argCount*sizeof(const char*));
|
||||||
unsigned filenameIdx = 0;
|
unsigned filenameIdx = 0;
|
||||||
unsigned forceStdout = 0;
|
unsigned forceStdout = 0;
|
||||||
|
unsigned providedInitialCLevel = 0;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int argNum;
|
int argNum;
|
||||||
filenameTable[0] = stdinmark;
|
filenameTable[0] = stdinmark;
|
||||||
@@ -1024,6 +1027,7 @@ int main(int argCount, const char* argv[])
|
|||||||
case 'i':
|
case 'i':
|
||||||
argument += 2;
|
argument += 2;
|
||||||
g_compressionLevel = readU32FromChar(&argument);
|
g_compressionLevel = readU32FromChar(&argument);
|
||||||
|
providedInitialCLevel = 1;
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
help();
|
help();
|
||||||
@@ -1062,6 +1066,20 @@ int main(int argCount, const char* argv[])
|
|||||||
filenameTable[filenameIdx++] = argument;
|
filenameTable[filenameIdx++] = argument;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* check initial, max, and min compression levels */
|
||||||
|
{
|
||||||
|
unsigned const minMaxInconsistent = g_minCLevel > g_maxCLevel;
|
||||||
|
unsigned const initialNotInRange = g_minCLevel > g_compressionLevel || g_maxCLevel < g_compressionLevel;
|
||||||
|
if (minMaxInconsistent || (initialNotInRange && providedInitialCLevel)) {
|
||||||
|
DISPLAY("Error: provided compression level parameters are invalid\n");
|
||||||
|
ret = 1;
|
||||||
|
goto _main_exit;
|
||||||
|
}
|
||||||
|
else if (initialNotInRange) {
|
||||||
|
g_compressionLevel = g_minCLevel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* error checking with number of files */
|
/* error checking with number of files */
|
||||||
if (filenameIdx > 1 && (outFilename != NULL && strcmp(outFilename, stdoutmark))) {
|
if (filenameIdx > 1 && (outFilename != NULL && strcmp(outFilename, stdoutmark))) {
|
||||||
DISPLAY("Error: multiple input files provided, cannot use specified output file\n");
|
DISPLAY("Error: multiple input files provided, cannot use specified output file\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user