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

Commit 00a0e54

Browse files
authoredJan 28, 2018
Merge pull request #644 from ethereum-mining/data-races
Data races fixes
2 parents d36ad47 + 144bbbd commit 00a0e54

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed
 

‎libethcore/Miner.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ class Miner: public Worker
184184
kick_miner();
185185
}
186186

187-
uint64_t hashCount() const { return m_hashCount; }
187+
uint64_t hashCount() const { return m_hashCount.load(std::memory_order_relaxed); }
188188

189-
void resetHashCount() { m_hashCount = 0; }
189+
void resetHashCount() { m_hashCount.store(0, std::memory_order_relaxed); }
190190

191191
virtual HwMonitor hwmon() = 0;
192192

@@ -207,7 +207,7 @@ class Miner: public Worker
207207

208208
WorkPackage work() const { Guard l(x_work); return m_work; }
209209

210-
void addHashCount(uint64_t _n) { m_hashCount += _n; }
210+
void addHashCount(uint64_t _n) { m_hashCount.fetch_add(_n, std::memory_order_relaxed); }
211211

212212
static unsigned s_dagLoadMode;
213213
static unsigned s_dagLoadIndex;
@@ -219,7 +219,7 @@ class Miner: public Worker
219219
std::chrono::high_resolution_clock::time_point workSwitchStart;
220220

221221
private:
222-
uint64_t m_hashCount = 0;
222+
std::atomic<uint64_t> m_hashCount = {0};
223223

224224
WorkPackage m_work;
225225
mutable Mutex x_work;

‎libstratum/EthStratumClient.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ EthStratumClient::EthStratumClient(Farm* f, MinerType m, string const & host, st
4040
p_active = &m_primary;
4141

4242
m_authorized = false;
43-
m_connected = false;
4443
m_pending = 0;
4544
m_maxRetries = retries;
4645
m_worktimeout = worktimeout;
@@ -105,7 +104,7 @@ void EthStratumClient::reconnect()
105104
m_io_service.reset();
106105
//m_socket.close(); // leads to crashes on Linux
107106
m_authorized = false;
108-
m_connected = false;
107+
m_connected.store(false, std::memory_order_relaxed);
109108

110109
if (!m_failover.host.empty())
111110
{
@@ -138,7 +137,7 @@ void EthStratumClient::reconnect()
138137
void EthStratumClient::disconnect()
139138
{
140139
cnote << "Disconnecting";
141-
m_connected = false;
140+
m_connected.store(false, std::memory_order_relaxed);
142141
m_running = false;
143142
if (p_farm->isMining())
144143
{
@@ -170,7 +169,7 @@ void EthStratumClient::connect_handler(const boost::system::error_code& ec, tcp:
170169

171170
if (!ec)
172171
{
173-
m_connected = true;
172+
m_connected.store(true, std::memory_order_relaxed);
174173
cnote << "Connected to stratum server " + i->host_name() + ":" + p_active->port;
175174
if (!p_farm->isMining())
176175
{
@@ -282,13 +281,13 @@ void EthStratumClient::readResponse(const boost::system::error_code& ec, std::si
282281
{
283282
cwarn << "Discarding incomplete response";
284283
}
285-
if (m_connected)
284+
if (m_connected.load(std::memory_order_relaxed))
286285
readline();
287286
}
288287
else
289288
{
290289
cwarn << "Read response failed: " + ec.message();
291-
if (m_connected)
290+
if (m_connected.load(std::memory_order_relaxed))
292291
reconnect();
293292
}
294293
}

‎libstratum/EthStratumClient.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class EthStratumClient
2626
void setFailover(string const & host, string const & port, string const & user, string const & pass);
2727

2828
bool isRunning() { return m_running; }
29-
bool isConnected() { return m_connected && m_authorized; }
29+
bool isConnected() { return m_connected.load(std::memory_order_relaxed) && m_authorized; }
3030
h256 currentHeaderHash() { return m_current.header; }
3131
bool current() { return static_cast<bool>(m_current); }
3232
bool submitHashrate(string const & rate);
@@ -54,7 +54,7 @@ class EthStratumClient
5454
string m_worker; // eth-proxy only;
5555

5656
bool m_authorized;
57-
bool m_connected;
57+
std::atomic<bool> m_connected = {false};
5858
bool m_running = true;
5959

6060
int m_retries = 0;

0 commit comments

Comments
 (0)
This repository has been archived.