From f046b97dcedde087e6f0a40312b96150ed03be19 Mon Sep 17 00:00:00 2001 From: Christopher Gurnee Date: Tue, 26 Jul 2016 12:28:19 -0400 Subject: [PATCH] disable multithreading for very small files --- installer/HashCheck.nsi | 6 ++-- libs/WinHash.cpp | 62 ++++++++++++++++++++++------------------- license.txt | 2 +- version.h | 4 +-- 4 files changed, 40 insertions(+), 34 deletions(-) diff --git a/installer/HashCheck.nsi b/installer/HashCheck.nsi index 3ee2aa8..53b5b08 100644 --- a/installer/HashCheck.nsi +++ b/installer/HashCheck.nsi @@ -53,15 +53,15 @@ FunctionEnd !insertmacro MUI_LANGUAGE "Ukrainian" !insertmacro MUI_LANGUAGE "Catalan" -VIProductVersion "2.3.2.11" +VIProductVersion "2.3.2.12" VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "HashCheck Shell Extension" -VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductVersion" "2.3.2.11" +VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductVersion" "2.3.2.12" VIAddVersionKey /LANG=${LANG_ENGLISH} "Comments" "Installer distributed from https://github.com/gurnec/HashCheck/releases" VIAddVersionKey /LANG=${LANG_ENGLISH} "CompanyName" "" VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalTrademarks" "" VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "Copyright © Kai Liu, Christopher Gurnee, Tim Schlueter. All rights reserved." VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "Installer (x86/x64) from https://github.com/gurnec/HashCheck/releases" -VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "2.3.2.11" +VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "2.3.2.12" ; With solid compression, files that are required before the ; actual installation should be stored first in the data block, diff --git a/libs/WinHash.cpp b/libs/WinHash.cpp index 26eec45..0c60e78 100644 --- a/libs/WinHash.cpp +++ b/libs/WinHash.cpp @@ -134,46 +134,52 @@ VOID WHAPI WHInitEx( PWHCTXEX pContext ) VOID WHAPI WHUpdateEx( PWHCTXEX pContext, PCBYTE pbIn, UINT cbIn ) { #if _MSC_VER >= 1600 - auto task_WHUpdateSHA512 = concurrency::make_task([&] { WHUpdateSHA512(&pContext->ctxSHA512, pbIn, cbIn); } ); - auto task_WHUpdateSHA256 = concurrency::make_task([&] { WHUpdateSHA256(&pContext->ctxSHA256, pbIn, cbIn); } ); - auto task_WHUpdateSHA1 = concurrency::make_task([&] { WHUpdateSHA1 (&pContext->ctxSHA1, pbIn, cbIn); } ); - auto task_WHUpdateMD5 = concurrency::make_task([&] { WHUpdateMD5 (&pContext->ctxMD5, pbIn, cbIn); } ); - auto task_WHUpdateCRC32 = concurrency::make_task([&] { WHUpdateCRC32 (&pContext->ctxCRC32, pbIn, cbIn); } ); + if (cbIn > 384u) { // determined experimentally--smaller than this and multithreading doesn't help, but ymmv - concurrency::structured_task_group hashing_task_group; + auto task_WHUpdateSHA512 = concurrency::make_task([&] { WHUpdateSHA512(&pContext->ctxSHA512, pbIn, cbIn); } ); + auto task_WHUpdateSHA256 = concurrency::make_task([&] { WHUpdateSHA256(&pContext->ctxSHA256, pbIn, cbIn); } ); + auto task_WHUpdateSHA1 = concurrency::make_task([&] { WHUpdateSHA1 (&pContext->ctxSHA1, pbIn, cbIn); } ); + auto task_WHUpdateMD5 = concurrency::make_task([&] { WHUpdateMD5 (&pContext->ctxMD5, pbIn, cbIn); } ); + auto task_WHUpdateCRC32 = concurrency::make_task([&] { WHUpdateCRC32 (&pContext->ctxCRC32, pbIn, cbIn); } ); - if (pContext->flags & WHEX_CHECKSHA512) - hashing_task_group.run(task_WHUpdateSHA512); + concurrency::structured_task_group hashing_task_group; - if (pContext->flags & WHEX_CHECKSHA256) - hashing_task_group.run(task_WHUpdateSHA256); + if (pContext->flags & WHEX_CHECKSHA512) + hashing_task_group.run(task_WHUpdateSHA512); - if (pContext->flags & WHEX_CHECKSHA1) - hashing_task_group.run(task_WHUpdateSHA1); + if (pContext->flags & WHEX_CHECKSHA256) + hashing_task_group.run(task_WHUpdateSHA256); - if (pContext->flags & WHEX_CHECKMD5) - hashing_task_group.run(task_WHUpdateMD5); + if (pContext->flags & WHEX_CHECKSHA1) + hashing_task_group.run(task_WHUpdateSHA1); - if (pContext->flags & WHEX_CHECKCRC32) - hashing_task_group.run(task_WHUpdateCRC32); + if (pContext->flags & WHEX_CHECKMD5) + hashing_task_group.run(task_WHUpdateMD5); - hashing_task_group.wait(); + if (pContext->flags & WHEX_CHECKCRC32) + hashing_task_group.run(task_WHUpdateCRC32); -#else - if (pContext->flags & WHEX_CHECKCRC32) - WHUpdateCRC32(&pContext->ctxCRC32, pbIn, cbIn); + hashing_task_group.wait(); + } - if (pContext->flags & WHEX_CHECKMD5) - WHUpdateMD5(&pContext->ctxMD5, pbIn, cbIn); + else { +#endif + if (pContext->flags & WHEX_CHECKCRC32) + WHUpdateCRC32(&pContext->ctxCRC32, pbIn, cbIn); - if (pContext->flags & WHEX_CHECKSHA1) - WHUpdateSHA1(&pContext->ctxSHA1, pbIn, cbIn); + if (pContext->flags & WHEX_CHECKMD5) + WHUpdateMD5(&pContext->ctxMD5, pbIn, cbIn); - if (pContext->flags & WHEX_CHECKSHA256) - WHUpdateSHA256(&pContext->ctxSHA256, pbIn, cbIn); + if (pContext->flags & WHEX_CHECKSHA1) + WHUpdateSHA1(&pContext->ctxSHA1, pbIn, cbIn); - if (pContext->flags & WHEX_CHECKSHA512) - WHUpdateSHA512(&pContext->ctxSHA512, pbIn, cbIn); + if (pContext->flags & WHEX_CHECKSHA256) + WHUpdateSHA256(&pContext->ctxSHA256, pbIn, cbIn); + + if (pContext->flags & WHEX_CHECKSHA512) + WHUpdateSHA512(&pContext->ctxSHA512, pbIn, cbIn); +#if _MSC_VER >= 1600 + } #endif } diff --git a/license.txt b/license.txt index cb0c1ac..942072c 100644 --- a/license.txt +++ b/license.txt @@ -1,7 +1,7 @@ HashCheck Shell Extension Copyright (C) 2008-2009 Kai Liu. All rights reserved. -Copyright (C) 2014 Christopher Gurnee. All rights reserved. +Copyright (C) 2014, 2016 Christopher Gurnee. All rights reserved. Copyright (C) 2014 Software Development Laboratories ("Fish" (David B. Trout)) Copyright (C) 2016 Tim Schlueter. All rights reserved. diff --git a/version.h b/version.h index fb2fff1..aaacacb 100644 --- a/version.h +++ b/version.h @@ -12,10 +12,10 @@ #define HASHCHECK_NAME_STR "HashCheck Shell Extension" // Full version: MUST be in the form of major,minor,revision,build -#define HASHCHECK_VERSION_FULL 2,3,2,11 +#define HASHCHECK_VERSION_FULL 2,3,2,12 // String version: May be any suitable string -#define HASHCHECK_VERSION_STR "2.3.2.11" +#define HASHCHECK_VERSION_STR "2.3.2.12" #ifdef _USRDLL // PE version: MUST be in the form of major.minor