From: CryptoManiac Date: Fri, 2 Oct 2015 08:25:15 +0000 (-0700) Subject: Allocate workers dynamically. X-Git-Tag: nvc-v0.5.5~67 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=a82b48504a17969d2f9efea60e72921cd446c796;hp=144f5f66954f40fc37431916917a0f1d7d034533 Allocate workers dynamically. --- diff --git a/src/kernel.cpp b/src/kernel.cpp index 79d8e58..55904e1 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -519,14 +519,16 @@ bool ScanMidstateForward(SHA256_CTX &ctx, uint32_t nBits, uint32_t nInputTxTime, { // TODO: custom threads amount + uint32_t nThreads = boost::thread::hardware_concurrency(); + uint32_t nBegin = SearchInterval.first; uint32_t nEnd = SearchInterval.second; uint32_t nPart = (nEnd - nBegin) / 4; - ScanMidstateWorker workers[4]; + ScanMidstateWorker *workers = new ScanMidstateWorker[nThreads]; boost::thread_group group; - for(int i = 0; i<4; i++) + for(size_t i = 0; i < nThreads; i++) { uint32_t nIntervalBegin = nBegin + nPart * i; uint32_t nIntervalEnd = nBegin + nPart * (i + 1); @@ -540,12 +542,14 @@ bool ScanMidstateForward(SHA256_CTX &ctx, uint32_t nBits, uint32_t nInputTxTime, group.join_all(); solutions.clear(); - for(int i = 0; i<4; i++) + for(size_t i = 0; i < nThreads; i++) { std::vector > ws = workers[i].GetSolutions(); solutions.insert(solutions.end(), ws.begin(), ws.end()); } + delete [] workers; + if (solutions.size() == 0) { // no solutions