Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
mutex changes
  • Loading branch information
mining-visualizer committed Apr 14, 2018
1 parent cf9bdd0 commit 4e5a958
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion 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()
Expand Down
2 changes: 1 addition & 1 deletion libethcore/EthashGPUMiner.cpp
Expand Up @@ -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);
Expand Down
35 changes: 18 additions & 17 deletions libethcore/Farm.h
Expand Up @@ -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);
}


Expand All @@ -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]";
}
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand All @@ -637,8 +640,6 @@ class GenericFarm
shouldStop = m_opMode == OperationMode::Solo;
}

x_minerWork.unlock();

return shouldStop;

}
Expand Down Expand Up @@ -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<bool> m_isMining = {false};
Expand Down

0 comments on commit 4e5a958

Please sign in to comment.