Added new nonce allocation method for dynamic/variable threads.
This commit is contained in:
parent
8e2219b7c4
commit
6f27037f07
10 changed files with 336 additions and 95 deletions
83
src/crypto/common/Nonce.cpp
Normal file
83
src/crypto/common/Nonce.cpp
Normal file
|
@ -0,0 +1,83 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#include "crypto/common/Nonce.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
std::atomic<uint64_t> Nonce::m_sequence;
|
||||
uint32_t Nonce::m_nonces[2] = { 0, 0 };
|
||||
|
||||
|
||||
static uv_mutex_t mutex;
|
||||
static Nonce nonce;
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::Nonce::Nonce()
|
||||
{
|
||||
m_sequence = 1;
|
||||
|
||||
uv_mutex_init(&mutex);
|
||||
}
|
||||
|
||||
|
||||
uint32_t xmrig::Nonce::next(uint8_t index, uint32_t nonce, uint32_t reserveCount, bool nicehash)
|
||||
{
|
||||
uint32_t next;
|
||||
|
||||
uv_mutex_lock(&mutex);
|
||||
|
||||
if (nicehash) {
|
||||
next = (nonce & 0xFF000000) | m_nonces[index];
|
||||
}
|
||||
else {
|
||||
next = m_nonces[index];
|
||||
}
|
||||
|
||||
m_nonces[index] += reserveCount;
|
||||
|
||||
uv_mutex_unlock(&mutex);
|
||||
|
||||
return next;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Nonce::reset(uint8_t index)
|
||||
{
|
||||
uv_mutex_lock(&mutex);
|
||||
|
||||
m_nonces[index] = 0;
|
||||
m_sequence++;
|
||||
|
||||
uv_mutex_unlock(&mutex);
|
||||
}
|
57
src/crypto/common/Nonce.h
Normal file
57
src/crypto/common/Nonce.h
Normal file
|
@ -0,0 +1,57 @@
|
|||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_NONCE_H
|
||||
#define XMRIG_NONCE_H
|
||||
|
||||
|
||||
#include <atomic>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class Nonce
|
||||
{
|
||||
public:
|
||||
Nonce();
|
||||
|
||||
static inline bool isOutdated(uint64_t sequence) { return m_sequence.load(std::memory_order_relaxed) != sequence; }
|
||||
static inline uint64_t sequence() { return m_sequence.load(std::memory_order_relaxed); }
|
||||
static inline void stop() { m_sequence = 0; }
|
||||
static inline void touch() { m_sequence++; }
|
||||
|
||||
static uint32_t next(uint8_t index, uint32_t nonce, uint32_t reserveCount, bool nicehash);
|
||||
static void reset(uint8_t index);
|
||||
|
||||
private:
|
||||
static uint32_t m_nonces[2];
|
||||
static std::atomic<uint64_t> m_sequence;
|
||||
};
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif /* XMRIG_NONCE_H */
|
Loading…
Add table
Add a link
Reference in a new issue