|
|
@ -26,6 +26,7 @@ |
|
|
|
#include <list> |
|
|
|
#include <atomic> |
|
|
|
#include <libdevcore/Common.h> |
|
|
|
#include <libdevcore/Worker.h> |
|
|
|
#include <libethcore/CommonEth.h> |
|
|
|
#include "State.h" |
|
|
|
|
|
|
@ -74,38 +75,38 @@ public: |
|
|
|
* @threadsafe |
|
|
|
* @todo Signal Miner to restart once with condition variables. |
|
|
|
*/ |
|
|
|
class Miner |
|
|
|
class Miner: Worker |
|
|
|
{ |
|
|
|
public: |
|
|
|
/// Null constructor.
|
|
|
|
Miner(): m_host(nullptr), m_id(0) {} |
|
|
|
Miner(): m_host(nullptr) {} |
|
|
|
|
|
|
|
/// Constructor.
|
|
|
|
Miner(MinerHost* _host, unsigned _id = 0); |
|
|
|
|
|
|
|
/// Move-constructor.
|
|
|
|
Miner(Miner&& _m) { std::swap(m_host, _m.m_host); std::swap(m_id, _m.m_id); } |
|
|
|
Miner(Miner&& _m): Worker((Worker&&)_m) { std::swap(m_host, _m.m_host); } |
|
|
|
|
|
|
|
/// Move-assignment.
|
|
|
|
Miner& operator=(Miner&& _m) { std::swap(m_host, _m.m_host); std::swap(m_id, _m.m_id); return *this; } |
|
|
|
Miner& operator=(Miner&& _m) { Worker::operator=((Worker&&)_m); std::swap(m_host, _m.m_host); return *this; } |
|
|
|
|
|
|
|
/// Destructor. Stops miner.
|
|
|
|
~Miner() { stop(); } |
|
|
|
|
|
|
|
/// Setup its basics.
|
|
|
|
void setup(MinerHost* _host, unsigned _id = 0) { m_host = _host; m_id = _id; } |
|
|
|
void setup(MinerHost* _host, unsigned _id = 0) { m_host = _host; setName("miner-" + toString(_id)); } |
|
|
|
|
|
|
|
/// Start mining.
|
|
|
|
void start(); |
|
|
|
void start() { startWorking(); } |
|
|
|
|
|
|
|
/// Stop mining.
|
|
|
|
void stop(); |
|
|
|
void stop() { stopWorking(); } |
|
|
|
|
|
|
|
/// Call to notify Miner of a state change.
|
|
|
|
void noteStateChange() { m_miningStatus = Preparing; } |
|
|
|
|
|
|
|
/// @returns true iff the mining has been start()ed. It may still not be actually mining, depending on the host's turbo() & force().
|
|
|
|
bool isRunning() { return !!m_work; } |
|
|
|
bool isRunning() { return isWorking(); } |
|
|
|
|
|
|
|
/// @returns true if mining is complete.
|
|
|
|
bool isComplete() const { return m_miningStatus == Mined; } |
|
|
@ -121,14 +122,9 @@ public: |
|
|
|
|
|
|
|
private: |
|
|
|
/// Do some work on the mining.
|
|
|
|
void work(); |
|
|
|
virtual void doWork(); |
|
|
|
|
|
|
|
MinerHost* m_host = nullptr; ///< Our host.
|
|
|
|
unsigned m_id = 0; ///< Our identity.
|
|
|
|
|
|
|
|
std::mutex x_work; ///< Mutex protecting the creation of the work thread.
|
|
|
|
std::unique_ptr<std::thread> m_work; ///< The work thread.
|
|
|
|
bool m_stop = false; ///< Stop working?
|
|
|
|
|
|
|
|
enum MiningStatus { Preparing, Mining, Mined, Stopping, Stopped }; |
|
|
|
MiningStatus m_miningStatus = Preparing;///< TODO: consider mutex/atomic variable.
|
|
|
|