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 {
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
static bool done = false;
|
class BenchStatePrivate
|
||||||
static std::mutex mutex;
|
{
|
||||||
static std::shared_ptr<Async> async;
|
public:
|
||||||
static uint32_t remaining = 0;
|
BenchStatePrivate(IBenchListener *listener, uint32_t size) :
|
||||||
static uint64_t doneTime = 0;
|
listener(listener),
|
||||||
static uint64_t result = 0;
|
size(size)
|
||||||
static uint64_t topDiff = 0;
|
{}
|
||||||
|
|
||||||
|
|
||||||
IBenchListener *BenchState::m_listener = nullptr;
|
IBenchListener *listener;
|
||||||
uint32_t BenchState::m_size = 0;
|
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
|
} // namespace xmrig
|
||||||
|
@ -52,7 +62,13 @@ uint32_t BenchState::m_size = 0;
|
||||||
|
|
||||||
bool xmrig::BenchState::isDone()
|
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)
|
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>([] {
|
d_ptr->async = std::make_shared<Async>([] {
|
||||||
m_listener->onBenchDone(result, topDiff, doneTime);
|
d_ptr->listener->onBenchDone(d_ptr->result, d_ptr->topDiff, d_ptr->doneTime);
|
||||||
async.reset();
|
|
||||||
xmrig::done = true;
|
destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
const uint64_t ts = Chrono::steadyMSecs();
|
const uint64_t ts = Chrono::steadyMSecs();
|
||||||
m_listener->onBenchReady(ts, remaining, backend);
|
d_ptr->listener->onBenchReady(ts, d_ptr->remaining, backend);
|
||||||
|
|
||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
@ -90,23 +106,39 @@ uint64_t xmrig::BenchState::start(size_t threads, const IBackend *backend)
|
||||||
|
|
||||||
void xmrig::BenchState::destroy()
|
void xmrig::BenchState::destroy()
|
||||||
{
|
{
|
||||||
xmrig::done = true;
|
delete d_ptr;
|
||||||
async.reset();
|
d_ptr = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void xmrig::BenchState::done(uint64_t data, uint64_t diff, uint64_t ts)
|
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;
|
d_ptr->result ^= data;
|
||||||
doneTime = std::max(doneTime, ts);
|
d_ptr->doneTime = std::max(d_ptr->doneTime, ts);
|
||||||
topDiff = std::max(topDiff, diff);
|
d_ptr->topDiff = std::max(d_ptr->topDiff, diff);
|
||||||
--remaining;
|
--d_ptr->remaining;
|
||||||
|
|
||||||
if (remaining == 0) {
|
if (d_ptr->remaining == 0) {
|
||||||
async->send();
|
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:
|
public:
|
||||||
static bool isDone();
|
static bool isDone();
|
||||||
|
static uint32_t size();
|
||||||
static uint64_t referenceHash(const Algorithm &algo, uint32_t size, uint32_t threads);
|
static uint64_t referenceHash(const Algorithm &algo, uint32_t size, uint32_t threads);
|
||||||
static uint64_t start(size_t threads, const IBackend *backend);
|
static uint64_t start(size_t threads, const IBackend *backend);
|
||||||
static void destroy();
|
static void destroy();
|
||||||
static void done(uint64_t data, uint64_t diff, uint64_t ts);
|
static void done(uint64_t data, uint64_t diff, uint64_t ts);
|
||||||
|
static void init(IBenchListener *listener, uint32_t size);
|
||||||
inline static uint32_t size() { return m_size; }
|
static void setSize(uint32_t 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;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -51,8 +51,7 @@ xmrig::BenchClient::BenchClient(const std::shared_ptr<BenchConfig> &benchmark, I
|
||||||
blob[Job::kMaxSeedSize * 2] = '\0';
|
blob[Job::kMaxSeedSize * 2] = '\0';
|
||||||
m_job.setSeedHash(blob.data());
|
m_job.setSeedHash(blob.data());
|
||||||
|
|
||||||
BenchState::setListener(this);
|
BenchState::init(this, m_benchmark->size());
|
||||||
BenchState::setSize(m_benchmark->size());
|
|
||||||
|
|
||||||
# ifdef XMRIG_FEATURE_HTTP
|
# ifdef XMRIG_FEATURE_HTTP
|
||||||
if (m_benchmark->isSubmit()) {
|
if (m_benchmark->isSubmit()) {
|
||||||
|
|
Loading…
Reference in a new issue