@@ -44,6 +44,10 @@ using namespace std;
44
44
using namespace dev ;
45
45
using namespace dev ::eth;
46
46
47
+ boost::asio::io_service g_io_service; // The IO service itself
48
+ dev::eth::Farm* g_farm;
49
+ dev::eth::PoolManager* g_mgr;
50
+
47
51
struct MiningChannel : public LogChannel
48
52
{
49
53
static const char * name () { return EthGreen " m" ; }
@@ -70,7 +74,7 @@ class MinerCLI
70
74
Stratum
71
75
};
72
76
73
- MinerCLI () : m_io_work(m_io_service), m_io_work_timer(m_io_service ), m_io_strand(m_io_service )
77
+ MinerCLI () : m_io_work_timer(g_io_service ), m_io_strand(g_io_service )
74
78
{
75
79
// Post first deadline timer to give io_service
76
80
// initial work
@@ -79,10 +83,10 @@ class MinerCLI
79
83
boost::bind (&MinerCLI::io_work_timer_handler, this , boost::asio::placeholders::error)));
80
84
81
85
// Start io_service in it's own thread
82
- m_io_thread = std::thread{boost::bind (&boost::asio::io_service::run, &m_io_service )};
86
+ m_io_thread = std::thread{boost::bind (&boost::asio::io_service::run, &g_io_service )};
83
87
84
88
// Io service is now live and running
85
- // All components using io_service should post to reference of m_io_service
89
+ // All components using io_service should post to reference of g_io_service
86
90
// and should not start/stop or even join threads (which heavily time consuming)
87
91
}
88
92
@@ -101,7 +105,7 @@ class MinerCLI
101
105
void stop_io_service ()
102
106
{
103
107
// Here we stop all io_service's related activities
104
- m_io_service .stop ();
108
+ g_io_service .stop ();
105
109
m_io_thread.join ();
106
110
}
107
111
@@ -772,7 +776,7 @@ class MinerCLI
772
776
genesis.setNumber (m_benchmarkBlock);
773
777
genesis.setDifficulty (u256 (1 ) << 64 );
774
778
775
- Farm f (m_io_service, m_show_hwmonitors, m_show_power);
779
+ g_farm = new Farm ( m_show_hwmonitors, m_show_power);
776
780
map<string, Farm::SealerDescriptor> sealers;
777
781
#if ETH_ETHASHCL
778
782
sealers[" opencl" ] = Farm::SealerDescriptor{&CLMiner::instances,
@@ -782,10 +786,13 @@ class MinerCLI
782
786
sealers[" cuda" ] = Farm::SealerDescriptor{&CUDAMiner::instances,
783
787
[](FarmFace& _farm, unsigned _index) { return new CUDAMiner (_farm, _index); }};
784
788
#endif
785
- f.setSealers (sealers);
786
- f.onSolutionFound ([&](Solution, unsigned const & miner_index) { (void )miner_index; return false ; });
789
+ g_farm->setSealers (sealers);
790
+ g_farm->onSolutionFound ([&](Solution, unsigned const & miner_index) {
791
+ (void )miner_index;
792
+ return false ;
793
+ });
787
794
788
- f. setTStartTStop (m_tstart, m_tstop);
795
+ g_farm-> setTStartTStop (m_tstart, m_tstop);
789
796
790
797
string platformInfo = _m == MinerType::CL ? " CL" : " CUDA" ;
791
798
cout << " Benchmarking on platform: " << platformInfo << endl;
@@ -794,9 +801,9 @@ class MinerCLI
794
801
// genesis.prep();
795
802
796
803
if (_m == MinerType::CL)
797
- f. start (" opencl" , false );
804
+ g_farm-> start (" opencl" , false );
798
805
else if (_m == MinerType::CUDA)
799
- f. start (" cuda" , false );
806
+ g_farm-> start (" cuda" , false );
800
807
801
808
WorkPackage current = WorkPackage (genesis);
802
809
@@ -809,14 +816,14 @@ class MinerCLI
809
816
{
810
817
current.header = h256::random ();
811
818
current.boundary = genesis.boundary ();
812
- f. setWork (current);
819
+ g_farm-> setWork (current);
813
820
if (!i)
814
821
cout << " Warming up..." << endl;
815
822
else
816
823
cout << " Trial " << i << " ... " << flush << endl;
817
824
this_thread::sleep_for (chrono::seconds (i ? _trialDuration : _warmupDuration));
818
825
819
- auto mp = f. miningProgress ();
826
+ auto mp = g_farm-> miningProgress ();
820
827
if (!i)
821
828
continue ;
822
829
auto rate = uint64_t (mp.hashRate );
@@ -857,8 +864,7 @@ class MinerCLI
857
864
858
865
if (m_mode == OperationMode::Stratum)
859
866
{
860
- client = new EthStratumClient (
861
- m_io_service, m_worktimeout, m_responsetimeout, m_report_hashrate);
867
+ client = new EthStratumClient (m_worktimeout, m_responsetimeout, m_report_hashrate);
862
868
}
863
869
else if (m_mode == OperationMode::Farm)
864
870
{
@@ -883,46 +889,45 @@ class MinerCLI
883
889
}
884
890
885
891
// sealers, m_minerType
886
- Farm f (m_io_service, m_show_hwmonitors, m_show_power);
887
- f. setSealers (sealers);
892
+ g_farm = new Farm ( m_show_hwmonitors, m_show_power);
893
+ g_farm-> setSealers (sealers);
888
894
889
- PoolManager mgr (m_io_service, client, f , m_minerType, m_maxFarmRetries, m_failovertimeout);
895
+ g_mgr = new PoolManager (client , m_minerType, m_maxFarmRetries, m_failovertimeout);
890
896
891
- f. setTStartTStop (m_tstart, m_tstop);
897
+ g_farm-> setTStartTStop (m_tstart, m_tstop);
892
898
893
899
// If we are in simulation mode we add a fake connection
894
900
if (m_mode == OperationMode::Simulation)
895
901
{
896
902
URI con (URI (" http://-:0" ));
897
- mgr. clearConnections ();
898
- mgr. addConnection (con);
903
+ g_mgr-> clearConnections ();
904
+ g_mgr-> addConnection (con);
899
905
}
900
906
else
901
907
{
902
908
for (auto conn : m_endpoints)
903
909
{
904
910
cnote << " Configured pool " << conn.Host () + " :" + to_string (conn.Port ());
905
- mgr. addConnection (conn);
911
+ g_mgr-> addConnection (conn);
906
912
}
907
913
}
908
914
909
915
#if API_CORE
910
916
911
- ApiServer api (m_io_service, m_api_address, abs (m_api_port), (m_api_port < 0 ) ? true : false ,
912
- m_api_password, f, mgr);
917
+ ApiServer api (m_api_address, m_api_port, m_api_password);
913
918
api.start ();
914
919
915
- http_server.run (m_http_address, m_http_port, &f, &mgr, m_show_hwmonitors, m_show_power);
920
+ http_server.run (m_http_address, m_http_port, m_show_hwmonitors, m_show_power);
916
921
917
922
#endif
918
923
919
924
// Start PoolManager
920
- mgr. start ();
925
+ g_mgr-> start ();
921
926
922
927
unsigned interval = m_displayInterval;
923
928
924
929
// Run CLI in loop
925
- while (g_running && mgr. isRunning ())
930
+ while (g_running && g_mgr-> isRunning ())
926
931
{
927
932
// Wait at the beginning of the loop to give some time
928
933
// services to start properly. Otherwise we get a "not-connected"
@@ -933,23 +938,23 @@ class MinerCLI
933
938
interval -= 2 ;
934
939
continue ;
935
940
}
936
- if (mgr. isConnected ())
941
+ if (g_mgr-> isConnected ())
937
942
{
938
- auto solstats = f. getSolutionStats ();
943
+ auto solstats = g_farm-> getSolutionStats ();
939
944
{
940
945
ostringstream os;
941
- os << f. miningProgress () << ' ' ;
946
+ os << g_farm-> miningProgress () << ' ' ;
942
947
if (!(g_logOptions & LOG_PER_GPU))
943
948
os << solstats << ' ' ;
944
- os << f. farmLaunchedFormatted ();
949
+ os << g_farm-> farmLaunchedFormatted ();
945
950
minelog << os.str ();
946
951
}
947
952
948
953
if (g_logOptions & LOG_PER_GPU)
949
954
{
950
955
ostringstream statdetails;
951
956
statdetails << " Solutions " << solstats << ' ' ;
952
- for (size_t i = 0 ; i < f. getMiners ().size (); i++)
957
+ for (size_t i = 0 ; i < g_farm-> getMiners ().size (); i++)
953
958
{
954
959
if (i) statdetails << " " ;
955
960
statdetails << " gpu" << i << " :" << solstats.getString (i);
@@ -975,7 +980,7 @@ class MinerCLI
975
980
976
981
#endif
977
982
978
- mgr. stop ();
983
+ g_mgr-> stop ();
979
984
stop_io_service ();
980
985
981
986
cnote << " Terminated!" ;
@@ -987,9 +992,6 @@ class MinerCLI
987
992
988
993
// / Global boost's io_service
989
994
std::thread m_io_thread; // The IO service thread
990
- boost::asio::io_service m_io_service; // The IO service itself
991
- boost::asio::io_service::work m_io_work; // The IO work which prevents io_service.run() to
992
- // return on no work thus terminating thread
993
995
boost::asio::deadline_timer m_io_work_timer; // A dummy timer to keep io_service with something
994
996
// to do and prevent io shutdown
995
997
boost::asio::io_service::strand m_io_strand; // A strand to serialize posts in multithreaded
0 commit comments