Make sure dataset init doesn't block start

This commit is contained in:
SChernykh 2022-03-24 20:55:35 +01:00
parent 028a5d0c88
commit 292e2580e5
2 changed files with 10 additions and 1 deletions

View file

@ -41,6 +41,7 @@ RandomX_Hasher::RandomX_Hasher(p2pool* pool)
, m_seed{}
, m_index(0)
, m_seedCounter(0)
, m_oldSeedCounter(0)
{
uint64_t memory_allocated = 0;
@ -223,6 +224,11 @@ void RandomX_Hasher::set_seed(const hash& seed)
numThreads /= 2;
}
// wait for set_old_seed() before initializing dataset
while (m_oldSeedCounter.load() == 0) {
std::this_thread::yield();
}
LOGINFO(1, log::LightCyan() << "running " << numThreads << " threads to update dataset");
ReadLock lock2(m_cacheLock);
@ -274,7 +280,7 @@ void RandomX_Hasher::set_old_seed(const hash& seed)
{
// set_seed() must go first, wait for it
while (m_seedCounter.load() == 0) {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
std::this_thread::yield();
}
LOGINFO(1, "old seed " << log::LightBlue() << seed);
@ -282,6 +288,8 @@ void RandomX_Hasher::set_old_seed(const hash& seed)
{
WriteLock lock(m_cacheLock);
m_oldSeedCounter.fetch_add(1);
const uint32_t old_index = m_index ^ 1;
m_seed[old_index] = seed;

View file

@ -90,6 +90,7 @@ private:
uint32_t m_index;
std::atomic<uint32_t> m_seedCounter;
std::atomic<uint32_t> m_oldSeedCounter;
};
#endif