@@ -160,39 +160,39 @@ class Farm: public FarmFace
160
160
}
161
161
}
162
162
163
- void collectHashRate ()
164
- {
165
- WorkingProgress p;
166
- Guard l2 (x_minerWork);
167
- p.ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now () - m_lastStart).count ();
168
- // Collect
169
- for (auto const & i : m_miners)
170
- {
171
- uint64_t minerHashCount = i->hashCount ();
172
- p.hashes += minerHashCount;
173
- p.minersHashes .push_back (minerHashCount);
174
- }
163
+ void collectHashRate ()
164
+ {
165
+ auto now = std::chrono::steady_clock::now ();
175
166
176
- // Reset
177
- for (auto const & i : m_miners)
178
- {
179
- i->resetHashCount ();
180
- }
181
- m_lastStart = std::chrono::steady_clock::now ();
167
+ std::lock_guard<std::mutex> lock (x_minerWork);
182
168
183
- if (p. hashes > 0 ) {
184
- m_lastProgresses. push_back (p );
185
- }
169
+ WorkingProgress p;
170
+ p. ms = std::chrono::duration_cast<std::chrono::milliseconds>(now - m_lastStart). count ( );
171
+ m_lastStart = now;
186
172
187
- // We smooth the hashrate over the last x seconds
188
- int allMs = 0 ;
189
- for (auto const & cp : m_lastProgresses) {
190
- allMs += cp.ms ;
191
- }
192
- if (allMs > m_hashrateSmoothInterval) {
193
- m_lastProgresses.erase (m_lastProgresses.begin ());
194
- }
195
- }
173
+ // Collect
174
+ for (auto const & i : m_miners)
175
+ {
176
+ uint64_t minerHashCount = i->hashCount ();
177
+ p.hashes += minerHashCount;
178
+ p.minersHashes .push_back (minerHashCount);
179
+ }
180
+
181
+ // Reset
182
+ for (auto const & i : m_miners)
183
+ i->resetHashCount ();
184
+
185
+ if (p.hashes > 0 )
186
+ m_lastProgresses.push_back (p);
187
+
188
+ // We smooth the hashrate over the last x seconds
189
+ int allMs = 0 ;
190
+ for (auto const & cp : m_lastProgresses)
191
+ allMs += cp.ms ;
192
+
193
+ if (allMs > m_hashrateSmoothInterval)
194
+ m_lastProgresses.erase (m_lastProgresses.begin ());
195
+ }
196
196
197
197
void processHashRate (const boost::system::error_code& ec) {
198
198
@@ -223,37 +223,36 @@ class Farm: public FarmFace
223
223
return m_isMining;
224
224
}
225
225
226
- /* *
227
- * @brief Get information on the progress of mining this work package.
228
- * @return The progress with mining so far.
229
- */
230
- WorkingProgress const & miningProgress (bool hwmon = false ) const
231
- {
232
- WorkingProgress p;
233
- p.ms = 0 ;
234
- p.hashes = 0 ;
235
- {
236
- Guard l2 (x_minerWork);
237
- for (auto const & i : m_miners) {
238
- p.minersHashes .push_back (0 );
239
- if (hwmon)
240
- p.minerMonitors .push_back (i->hwmon ());
241
- }
242
- }
243
-
244
- for (auto const & cp : m_lastProgresses) {
245
- p.ms += cp.ms ;
246
- p.hashes += cp.hashes ;
247
- for (unsigned int i = 0 ; i < cp.minersHashes .size (); i++)
248
- {
249
- p.minersHashes .at (i) += cp.minersHashes .at (i);
250
- }
251
- }
252
-
253
- Guard l (x_progress);
254
- m_progress = p;
255
- return m_progress;
256
- }
226
+ /* *
227
+ * @brief Get information on the progress of mining this work package.
228
+ * @return The progress with mining so far.
229
+ */
230
+ WorkingProgress const & miningProgress (bool hwmon = false ) const
231
+ {
232
+ std::lock_guard<std::mutex> lock (x_minerWork);
233
+ WorkingProgress p;
234
+ p.ms = 0 ;
235
+ p.hashes = 0 ;
236
+ for (auto const & i : m_miners)
237
+ {
238
+ p.minersHashes .push_back (0 );
239
+ if (hwmon)
240
+ p.minerMonitors .push_back (i->hwmon ());
241
+ }
242
+
243
+ for (auto const & cp : m_lastProgresses)
244
+ {
245
+ p.ms += cp.ms ;
246
+ p.hashes += cp.hashes ;
247
+ for (unsigned int i = 0 ; i < cp.minersHashes .size (); i++)
248
+ {
249
+ p.minersHashes .at (i) += cp.minersHashes .at (i);
250
+ }
251
+ }
252
+
253
+ m_progress = p;
254
+ return m_progress;
255
+ }
257
256
258
257
SolutionStats getSolutionStats () {
259
258
return m_solutionStats;
@@ -350,11 +349,8 @@ class Farm: public FarmFace
350
349
351
350
std::atomic<bool > m_isMining = {false };
352
351
353
- mutable Mutex x_progress;
354
352
mutable WorkingProgress m_progress;
355
353
356
- mutable Mutex x_hwmons;
357
-
358
354
SolutionFound m_onSolutionFound;
359
355
MinerRestart m_onMinerRestart;
360
356
0 commit comments