Skip to content
This repository was archived by the owner on Apr 24, 2022. It is now read-only.

Commit 98bed68

Browse files
committedSep 15, 2018
Use FarmFace singleton
1 parent 18d2b1c commit 98bed68

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed
 

‎libethash-cl/CLMiner.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ unsigned CLMiner::s_numInstances = 0;
261261
vector<int> CLMiner::s_devices(MAX_MINERS, -1);
262262
bool CLMiner::s_noBinary = false;
263263

264-
CLMiner::CLMiner(unsigned _index) : Miner("cl-", Farm::f(), _index) {}
264+
CLMiner::CLMiner(unsigned _index) : Miner("cl-", _index) {}
265265

266266
CLMiner::~CLMiner()
267267
{

‎libethash-cuda/CUDAMiner.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ struct CUDAChannel : public LogChannel
3535
};
3636
#define cudalog clog(CUDAChannel)
3737

38-
CUDAMiner::CUDAMiner(unsigned _index) : Miner("cuda-", Farm::f(), _index), m_light(getNumDevices())
39-
{}
38+
CUDAMiner::CUDAMiner(unsigned _index) : Miner("cuda-", _index), m_light(getNumDevices()) {}
4039

4140
CUDAMiner::~CUDAMiner()
4241
{

‎libethcore/Miner.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ unsigned Miner::s_dagCreateDevice = 0;
2929

3030
uint8_t* Miner::s_dagInHostMemory = nullptr;
3131

32+
FarmFace* FarmFace::m_this = nullptr;
33+
3234
bool Miner::s_exit = false;
3335

3436
bool Miner::s_noeval = false;

‎libethcore/Miner.h

+14-8
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ class Miner;
288288
class FarmFace
289289
{
290290
public:
291+
FarmFace() { m_this = this; }
292+
static FarmFace& f() { return *m_this; };
293+
291294
virtual ~FarmFace() = default;
292295
virtual unsigned get_tstart() = 0;
293296
virtual unsigned get_tstop() = 0;
@@ -300,6 +303,9 @@ class FarmFace
300303
virtual void failedSolution(unsigned _miner_index) = 0;
301304
virtual uint64_t get_nonce_scrambler() = 0;
302305
virtual unsigned get_segment_width() = 0;
306+
307+
private:
308+
static FarmFace* m_this;
303309
};
304310

305311
/**
@@ -312,8 +318,8 @@ class FarmFace
312318
class Miner : public Worker
313319
{
314320
public:
315-
Miner(std::string const& _name, FarmFace& _farm, size_t _index)
316-
: Worker(_name + std::to_string(_index)), m_index(_index), m_farmFace(_farm)
321+
Miner(std::string const& _name, size_t _index)
322+
: Worker(_name + std::to_string(_index)), m_index(_index)
317323
{
318324
}
319325

@@ -337,8 +343,8 @@ class Miner : public Worker
337343
// return farm.get_nonce_scrambler() + ((uint64_t) m_index << 40);
338344

339345
// Now segment size is adjustable
340-
m_work.startNonce = m_farmFace.get_nonce_scrambler() +
341-
((uint64_t)m_index << m_farmFace.get_segment_width());
346+
m_work.startNonce = FarmFace::f().get_nonce_scrambler() +
347+
((uint64_t)m_index << FarmFace::f().get_segment_width());
342348
}
343349

344350
if (g_logOptions & LOG_SWITCH_TIME)
@@ -355,14 +361,15 @@ class Miner : public Worker
355361
{
356362
/*
357363
cnote << "Setting temp" << temperature << " for gpu" << m_index <<
358-
" tstop=" << m_farmFace.get_tstop() << " tstart=" << m_farmFace.get_tstart();
364+
" tstop=" << FarmFace::f().get_tstop() << " tstart=" <<
365+
FarmFace::f().get_tstart();
359366
*/
360367
bool _wait_for_tstart_temp = (m_mining_paused.get_mining_paused() &
361368
MinigPauseReason::MINING_PAUSED_WAIT_FOR_T_START) ==
362369
MinigPauseReason::MINING_PAUSED_WAIT_FOR_T_START;
363370
if (!_wait_for_tstart_temp)
364371
{
365-
unsigned tstop = m_farmFace.get_tstop();
372+
unsigned tstop = FarmFace::f().get_tstop();
366373
if (tstop && temperature >= tstop)
367374
{
368375
cwarn << "Pause mining on gpu" << m_index << " : temperature " << temperature
@@ -372,7 +379,7 @@ class Miner : public Worker
372379
}
373380
else
374381
{
375-
unsigned tstart = m_farmFace.get_tstart();
382+
unsigned tstart = FarmFace::f().get_tstart();
376383
if (tstart && temperature <= tstart)
377384
{
378385
cnote << "(Re)starting mining on gpu" << m_index << " : temperature " << temperature
@@ -445,7 +452,6 @@ class Miner : public Worker
445452
static bool s_noeval;
446453

447454
const size_t m_index = 0;
448-
FarmFace& m_farmFace;
449455
std::chrono::steady_clock::time_point m_workSwitchStart;
450456
HwMonitorInfo m_hwmoninfo;
451457

0 commit comments

Comments
 (0)
This repository has been archived.