summaryrefslogtreecommitdiffstats
path: root/xmrstak/backend/globalStates.cpp
diff options
context:
space:
mode:
authorfireice-uk <fireice-uk@users.noreply.github.com>2018-05-30 21:18:45 +0100
committerGitHub <noreply@github.com>2018-05-30 21:18:45 +0100
commitc0ab1734332d6472225d8ac7394f6fcba71aabc9 (patch)
treeb53a4c37905a0cb5dfa6a66f514cf3dc1ea94a21 /xmrstak/backend/globalStates.cpp
parent26a5d65f12b2f19a0a3ece39a2bc64718796367b (diff)
parent4f34bd18024fa71a8cab81d5a0b86cf5c7d9370e (diff)
downloadxmr-stak-2.4.4.zip
xmr-stak-2.4.4.tar.gz
Merge pull request #1610 from fireice-uk/dev2.4.4
release 2.4.4
Diffstat (limited to 'xmrstak/backend/globalStates.cpp')
-rw-r--r--xmrstak/backend/globalStates.cpp31
1 files changed, 22 insertions, 9 deletions
diff --git a/xmrstak/backend/globalStates.cpp b/xmrstak/backend/globalStates.cpp
index 1ec7983..3bd7d0e 100644
--- a/xmrstak/backend/globalStates.cpp
+++ b/xmrstak/backend/globalStates.cpp
@@ -33,24 +33,37 @@
namespace xmrstak
{
+void globalStates::consume_work( miner_work& threadWork, uint64_t& currentJobId)
+{
+ jobLock.ReadLock();
+
+ threadWork = oGlobalWork;
+ currentJobId = iGlobalJobNo.load(std::memory_order_relaxed);
+
+ jobLock.UnLock();
+}
void globalStates::switch_work(miner_work& pWork, pool_data& dat)
{
- // iConsumeCnt is a basic lock-like polling mechanism just in case we happen to push work
- // faster than threads can consume them. This should never happen in real life.
- // Pool cant physically send jobs faster than every 250ms or so due to net latency.
-
- while (iConsumeCnt.load(std::memory_order_seq_cst) < iThreadCount)
- std::this_thread::sleep_for(std::chrono::milliseconds(100));
+ jobLock.WriteLock();
+ /* This notifies all threads that the job has changed.
+ * To avoid duplicated shared this must be done before the nonce is exchanged.
+ */
+ iGlobalJobNo++;
+
size_t xid = dat.pool_id;
dat.pool_id = pool_id;
pool_id = xid;
- dat.iSavedNonce = iGlobalNonce.exchange(dat.iSavedNonce, std::memory_order_seq_cst);
+ /* Maybe a worker thread is updating the nonce while we read it.
+ * To avoid duplicated share calculations the job ID is checked in the worker thread
+ * after the nonce is read.
+ */
+ dat.iSavedNonce = iGlobalNonce.exchange(dat.iSavedNonce, std::memory_order_relaxed);
oGlobalWork = pWork;
- iConsumeCnt.store(0, std::memory_order_seq_cst);
- iGlobalJobNo++;
+
+ jobLock.UnLock();
}
} // namespace xmrstak
OpenPOWER on IntegriCloud