From 4e5a9581bfd191a165ae4f147c890ce6dd8b8ead Mon Sep 17 00:00:00 2001 From: mvis Date: Sat, 14 Apr 2018 13:48:50 -0700 Subject: [PATCH] mutex changes --- CMakeLists.txt | 2 +- libethcore/EthashGPUMiner.cpp | 2 +- libethcore/Farm.h | 35 ++++++++++++++++++----------------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e0b471..72daa99 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # cmake global cmake_minimum_required(VERSION 2.8.12) -set(PROJECT_VERSION "2.1.9") +set(PROJECT_VERSION "2.1.10") if (${CMAKE_VERSION} VERSION_GREATER 3.0) cmake_policy(SET CMP0042 OLD) # fix MACOSX_RPATH cmake_policy(SET CMP0048 NEW) # allow VERSION argument in project() diff --git a/libethcore/EthashGPUMiner.cpp b/libethcore/EthashGPUMiner.cpp index 4a723de..5946c3b 100644 --- a/libethcore/EthashGPUMiner.cpp +++ b/libethcore/EthashGPUMiner.cpp @@ -140,7 +140,7 @@ bool EthashGPUMiner::report(h256 _nonce) h160 sender(m_farm->hashingAcct); bytes hash(32); keccak256_0xBitcoin(challenge, sender, _nonce, hash); - LogF << "Trace: EthashGPUMiner::report, challenge = " << toHex(challenge) << ", sender = " << sender.hex() + LogF << "Trace: EthashGPUMiner::report, challenge = " << toHex(challenge) << ", sender = " << sender.hex() << ", hash = " << toHex(hash) << ", target = " << target.hex() << ", miner[" << m_index << "]"; if (h256(hash) < target) return submitProof(_nonce); diff --git a/libethcore/Farm.h b/libethcore/Farm.h index a8a196e..b26a90e 100644 --- a/libethcore/Farm.h +++ b/libethcore/Farm.h @@ -204,12 +204,12 @@ class GenericFarm << ", target=" << std::hex << std::setw(16) << std::setfill('0') << upper64OfHash(_target); WriteGuard l(x_minerWork); - if (_challenge == challenge && _target == target) + if (_challenge == m_challenge && _target == m_target) return; - challenge = _challenge; - target = _target; + m_challenge = _challenge; + m_target = _target; for (auto const& m: m_miners) - m->setWork(challenge, target); + m->setWork(m_challenge, m_target); } @@ -227,7 +227,7 @@ class GenericFarm m_hashRates->init(); // can't call setWork until we've initialized the hash rates //for (auto const& m : m_miners) - // m->setWork_token(challenge, target); + // m->setWork_token(m_challenge, m_target); LogF << "Trace: GenericFarm.start [exit]"; } @@ -605,16 +605,19 @@ class GenericFarm *----------------------------------------------------------------------------------*/ bool submitProof(h256 _nonce, Miner* _m) { - // return true if miner should stop and wait for new work, false otherwise + // return true if miner should stop and wait for new work, false to keep mining bool shouldStop = false; LogF << "Trace: GenericFarm.submitProof - nonce = " << _nonce.hex().substr(0, 8) << ", miner = " << _m->index(); - if (!x_minerWork.try_lock()) - { - LogF << "Trace: GenericFarm.submitProof - mutex locked ... exiting"; - return shouldStop; - } + /* + we could block here if + - another miner found a solution and is submitting it + - the main loop is checking if a solution has been found + - setWork has been called with a new work package + */ + + WriteGuard l(x_minerWork); // check to see if the main loop is still processing a previous solution if (solutionMiner == -1) @@ -624,10 +627,10 @@ class GenericFarm solution = _nonce; if (m_opMode == OperationMode::Solo) { - challenge.clear(); + m_challenge.clear(); for (auto const& m : m_miners) if (m != _m) - m->setWork(challenge, target); + m->setWork(m_challenge, m_target); shouldStop = true; } else shouldStop = false; @@ -637,8 +640,6 @@ class GenericFarm shouldStop = m_opMode == OperationMode::Solo; } - x_minerWork.unlock(); - return shouldStop; } @@ -682,8 +683,8 @@ class GenericFarm private: mutable SharedMutex x_minerWork; miners_t m_miners; - h256 target; - bytes challenge; + h256 m_target; + bytes m_challenge; OperationMode m_opMode; std::atomic m_isMining = {false};