summaryrefslogtreecommitdiffstats
path: root/xmrstak/backend/globalStates.cpp
diff options
context:
space:
mode:
authorpsychocrypt <psychocryptHPC@gmail.com>2018-05-03 20:35:56 +0200
committerTimothy Pearson <tpearson@raptorengineering.com>2018-06-04 21:07:11 +0000
commitd43548fe1b0ccda74477a149379b852f5abc36f7 (patch)
treecd472b2e5a7776da256b313bb66ec90c937642a9 /xmrstak/backend/globalStates.cpp
parentd68036dfe013c4949fdc636a5f60e599555fe2ca (diff)
downloadxmr-stak-d43548fe1b0ccda74477a149379b852f5abc36f7.zip
xmr-stak-d43548fe1b0ccda74477a149379b852f5abc36f7.tar.gz
add read write lock class
add log class from Will Zhang: Package: cpputil Source: https://github.com/willzhang4a58/cpputil License: MIT License
Diffstat (limited to 'xmrstak/backend/globalStates.cpp')
-rw-r--r--xmrstak/backend/globalStates.cpp51
1 files changed, 6 insertions, 45 deletions
diff --git a/xmrstak/backend/globalStates.cpp b/xmrstak/backend/globalStates.cpp
index e60db8f..6058b7a 100644
--- a/xmrstak/backend/globalStates.cpp
+++ b/xmrstak/backend/globalStates.cpp
@@ -35,57 +35,18 @@ namespace xmrstak
void globalStates::consume_work( miner_work& threadWork, uint64_t& currentJobId)
{
- /* Only the executer thread which updates the job is ever setting iConsumeCnt
- * to 1000. In this case each consumer must wait until the job is fully updated.
- */
- uint64_t numConsumer = 0;
-
- /* Take care that we not consume a job if the job is updated.
- * If we leave the loop we have increased iConsumeCnt so that
- * the job will not be updated until we leave the method.
- */
- do{
- numConsumer = iConsumeCnt.load(std::memory_order_relaxed);
- if(numConsumer < 1000)
- {
- // register that thread try consume job data
- numConsumer = ++iConsumeCnt;
- if(numConsumer >= 1000)
- {
- iConsumeCnt--;
- // 11 is a arbitrary chosen prime number
- std::this_thread::sleep_for(std::chrono::milliseconds(11));
- }
- }
- else
- {
- // an other thread is preparing a new job, 11 is a arbitrary chosen prime number
- std::this_thread::sleep_for(std::chrono::milliseconds(11));
- }
- }
- while(numConsumer >= 1000);
+ jobLock.rdlock();
threadWork = oGlobalWork;
currentJobId = iGlobalJobNo.load(std::memory_order_relaxed);
- // signal that thread consumed work
- iConsumeCnt--;
+ jobLock.unlock();
}
void globalStates::switch_work(miner_work& pWork, pool_data& dat)
{
- /* 1000 is used to notify that the the job will be updated as soon
- * as all consumer (which currently coping oGlobalWork has copied
- * all data)
- */
- iConsumeCnt += 1000;
- // wait until all threads which entered consume_work are finished
- while (iConsumeCnt.load(std::memory_order_relaxed) > 1000)
- {
- // 7 is a arbitrary chosen prime number which is smaller than the consumer waiting time
- std::this_thread::sleep_for(std::chrono::milliseconds(7));
- }
- // BEGIN CRITICAL SECTION
+ jobLock.wrlock();
+
// this notifies all threads that the job has changed
iGlobalJobNo++;
@@ -100,8 +61,8 @@ void globalStates::switch_work(miner_work& pWork, pool_data& dat)
*/
dat.iSavedNonce = iGlobalNonce.exchange(dat.iSavedNonce, std::memory_order_relaxed);
oGlobalWork = pWork;
- // END CRITICAL SECTION: allow job consume
- iConsumeCnt -= 1000;
+
+ jobLock.unlock();
}
} // namespace xmrstak
OpenPOWER on IntegriCloud