mirror of
https://github.com/xmrig/xmrig.git
synced 2024-10-30 21:17:52 +00:00
Added BenchStatePrivate class.
This commit is contained in:
parent
05a2054057
commit
09b68f3cdb
3 changed files with 63 additions and 37 deletions
|
@ -33,17 +33,27 @@
|
|||
namespace xmrig {
|
||||
|
||||
|
||||
static bool done = false;
|
||||
static std::mutex mutex;
|
||||
static std::shared_ptr<Async> async;
|
||||
static uint32_t remaining = 0;
|
||||
static uint64_t doneTime = 0;
|
||||
static uint64_t result = 0;
|
||||
static uint64_t topDiff = 0;
|
||||
class BenchStatePrivate
|
||||
{
|
||||
public:
|
||||
BenchStatePrivate(IBenchListener *listener, uint32_t size) :
|
||||
listener(listener),
|
||||
size(size)
|
||||
{}
|
||||
|
||||
|
||||
IBenchListener *BenchState::m_listener = nullptr;
|
||||
uint32_t BenchState::m_size = 0;
|
||||
IBenchListener *listener;
|
||||
std::mutex mutex;
|
||||
std::shared_ptr<Async> async;
|
||||
uint32_t remaining = 0;
|
||||
uint32_t size;
|
||||
uint64_t doneTime = 0;
|
||||
uint64_t result = 0;
|
||||
uint64_t topDiff = 0;
|
||||
};
|
||||
|
||||
|
||||
static BenchStatePrivate *d_ptr = nullptr;
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
@ -52,7 +62,13 @@ uint32_t BenchState::m_size = 0;
|
|||
|
||||
bool xmrig::BenchState::isDone()
|
||||
{
|
||||
return xmrig::done;
|
||||
return d_ptr == nullptr;
|
||||
}
|
||||
|
||||
|
||||
uint32_t xmrig::BenchState::size()
|
||||
{
|
||||
return d_ptr ? d_ptr->size : 0U;
|
||||
}
|
||||
|
||||
|
||||
|
@ -71,18 +87,18 @@ uint64_t xmrig::BenchState::referenceHash(const Algorithm &algo, uint32_t size,
|
|||
|
||||
uint64_t xmrig::BenchState::start(size_t threads, const IBackend *backend)
|
||||
{
|
||||
assert(m_listener != nullptr);
|
||||
assert(d_ptr != nullptr);
|
||||
|
||||
remaining = static_cast<uint32_t>(threads);
|
||||
d_ptr->remaining = static_cast<uint32_t>(threads);
|
||||
|
||||
async = std::make_shared<Async>([] {
|
||||
m_listener->onBenchDone(result, topDiff, doneTime);
|
||||
async.reset();
|
||||
xmrig::done = true;
|
||||
d_ptr->async = std::make_shared<Async>([] {
|
||||
d_ptr->listener->onBenchDone(d_ptr->result, d_ptr->topDiff, d_ptr->doneTime);
|
||||
|
||||
destroy();
|
||||
});
|
||||
|
||||
const uint64_t ts = Chrono::steadyMSecs();
|
||||
m_listener->onBenchReady(ts, remaining, backend);
|
||||
d_ptr->listener->onBenchReady(ts, d_ptr->remaining, backend);
|
||||
|
||||
return ts;
|
||||
}
|
||||
|
@ -90,23 +106,39 @@ uint64_t xmrig::BenchState::start(size_t threads, const IBackend *backend)
|
|||
|
||||
void xmrig::BenchState::destroy()
|
||||
{
|
||||
xmrig::done = true;
|
||||
async.reset();
|
||||
delete d_ptr;
|
||||
d_ptr = nullptr;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::BenchState::done(uint64_t data, uint64_t diff, uint64_t ts)
|
||||
{
|
||||
assert(async && remaining > 0);
|
||||
assert(d_ptr != nullptr && d_ptr->async && d_ptr->remaining > 0);
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
std::lock_guard<std::mutex> lock(d_ptr->mutex);
|
||||
|
||||
result ^= data;
|
||||
doneTime = std::max(doneTime, ts);
|
||||
topDiff = std::max(topDiff, diff);
|
||||
--remaining;
|
||||
d_ptr->result ^= data;
|
||||
d_ptr->doneTime = std::max(d_ptr->doneTime, ts);
|
||||
d_ptr->topDiff = std::max(d_ptr->topDiff, diff);
|
||||
--d_ptr->remaining;
|
||||
|
||||
if (remaining == 0) {
|
||||
async->send();
|
||||
if (d_ptr->remaining == 0) {
|
||||
d_ptr->async->send();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xmrig::BenchState::init(IBenchListener *listener, uint32_t size)
|
||||
{
|
||||
assert(d_ptr == nullptr);
|
||||
|
||||
d_ptr = new BenchStatePrivate(listener, size);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::BenchState::setSize(uint32_t size)
|
||||
{
|
||||
assert(d_ptr != nullptr);
|
||||
|
||||
d_ptr->size = size;
|
||||
}
|
||||
|
|
|
@ -36,18 +36,13 @@ class BenchState
|
|||
{
|
||||
public:
|
||||
static bool isDone();
|
||||
static uint32_t size();
|
||||
static uint64_t referenceHash(const Algorithm &algo, uint32_t size, uint32_t threads);
|
||||
static uint64_t start(size_t threads, const IBackend *backend);
|
||||
static void destroy();
|
||||
static void done(uint64_t data, uint64_t diff, uint64_t ts);
|
||||
|
||||
inline static uint32_t size() { return m_size; }
|
||||
inline static void setListener(IBenchListener *listener) { m_listener = listener; }
|
||||
inline static void setSize(uint32_t size) { m_size = size; }
|
||||
|
||||
private:
|
||||
static IBenchListener *m_listener;
|
||||
static uint32_t m_size;
|
||||
static void init(IBenchListener *listener, uint32_t size);
|
||||
static void setSize(uint32_t size);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -51,8 +51,7 @@ xmrig::BenchClient::BenchClient(const std::shared_ptr<BenchConfig> &benchmark, I
|
|||
blob[Job::kMaxSeedSize * 2] = '\0';
|
||||
m_job.setSeedHash(blob.data());
|
||||
|
||||
BenchState::setListener(this);
|
||||
BenchState::setSize(m_benchmark->size());
|
||||
BenchState::init(this, m_benchmark->size());
|
||||
|
||||
# ifdef XMRIG_FEATURE_HTTP
|
||||
if (m_benchmark->isSubmit()) {
|
||||
|
|
Loading…
Reference in a new issue