mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-11-16 15:57:39 +00:00
Make sure dataset init doesn't block start
This commit is contained in:
parent
028a5d0c88
commit
292e2580e5
2 changed files with 10 additions and 1 deletions
|
@ -41,6 +41,7 @@ RandomX_Hasher::RandomX_Hasher(p2pool* pool)
|
||||||
, m_seed{}
|
, m_seed{}
|
||||||
, m_index(0)
|
, m_index(0)
|
||||||
, m_seedCounter(0)
|
, m_seedCounter(0)
|
||||||
|
, m_oldSeedCounter(0)
|
||||||
{
|
{
|
||||||
uint64_t memory_allocated = 0;
|
uint64_t memory_allocated = 0;
|
||||||
|
|
||||||
|
@ -223,6 +224,11 @@ void RandomX_Hasher::set_seed(const hash& seed)
|
||||||
numThreads /= 2;
|
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");
|
LOGINFO(1, log::LightCyan() << "running " << numThreads << " threads to update dataset");
|
||||||
|
|
||||||
ReadLock lock2(m_cacheLock);
|
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
|
// set_seed() must go first, wait for it
|
||||||
while (m_seedCounter.load() == 0) {
|
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);
|
LOGINFO(1, "old seed " << log::LightBlue() << seed);
|
||||||
|
@ -282,6 +288,8 @@ void RandomX_Hasher::set_old_seed(const hash& seed)
|
||||||
{
|
{
|
||||||
WriteLock lock(m_cacheLock);
|
WriteLock lock(m_cacheLock);
|
||||||
|
|
||||||
|
m_oldSeedCounter.fetch_add(1);
|
||||||
|
|
||||||
const uint32_t old_index = m_index ^ 1;
|
const uint32_t old_index = m_index ^ 1;
|
||||||
m_seed[old_index] = seed;
|
m_seed[old_index] = seed;
|
||||||
|
|
||||||
|
|
|
@ -90,6 +90,7 @@ private:
|
||||||
uint32_t m_index;
|
uint32_t m_index;
|
||||||
|
|
||||||
std::atomic<uint32_t> m_seedCounter;
|
std::atomic<uint32_t> m_seedCounter;
|
||||||
|
std::atomic<uint32_t> m_oldSeedCounter;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue