Added class JobResults.
This commit is contained in:
@ -35,11 +35,12 @@ set(HEADERS
|
||||
src/core/config/ConfigTransform.h
|
||||
src/core/config/usage.h
|
||||
src/core/Controller.h
|
||||
src/interfaces/IJobResultListener.h
|
||||
src/interfaces/IThread.h
|
||||
src/interfaces/IWorker.h
|
||||
src/Mem.h
|
||||
src/net/interfaces/IJobResultListener.h
|
||||
src/net/JobResult.h
|
||||
src/net/JobResults.h
|
||||
src/net/Network.h
|
||||
src/net/NetworkState.h
|
||||
src/net/strategies/DonateStrategy.h
|
||||
@ -90,6 +91,7 @@ set(SOURCES
|
||||
src/core/config/ConfigTransform.cpp
|
||||
src/core/Controller.cpp
|
||||
src/Mem.cpp
|
||||
src/net/JobResults.cpp
|
||||
src/net/Network.cpp
|
||||
src/net/NetworkState.cpp
|
||||
src/net/strategies/DonateStrategy.cpp
|
||||
|
@ -137,9 +137,11 @@ size_t xmrig::Algorithm::memory() const
|
||||
return CnAlgo<>::memory(m_id);
|
||||
}
|
||||
|
||||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
if (m_id == RX_WOW) {
|
||||
return 0x100000;
|
||||
}
|
||||
# endif
|
||||
|
||||
return 0x200000;
|
||||
}
|
||||
|
139
src/net/JobResults.cpp
Normal file
139
src/net/JobResults.cpp
Normal file
@ -0,0 +1,139 @@
|
||||
/* 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 <assert.h>
|
||||
#include <list>
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#include "base/tools/Handle.h"
|
||||
#include "net/interfaces/IJobResultListener.h"
|
||||
#include "net/JobResult.h"
|
||||
#include "net/JobResults.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class JobResultsPrivate
|
||||
{
|
||||
public:
|
||||
inline JobResultsPrivate()
|
||||
{
|
||||
uv_mutex_init(&m_mutex);
|
||||
|
||||
m_async = new uv_async_t;
|
||||
m_async->data = this;
|
||||
|
||||
uv_async_init(uv_default_loop(), m_async, JobResultsPrivate::onResult);
|
||||
}
|
||||
|
||||
|
||||
inline ~JobResultsPrivate()
|
||||
{
|
||||
Handle::close(m_async);
|
||||
}
|
||||
|
||||
|
||||
void setListener(IJobResultListener *listener)
|
||||
{
|
||||
m_listener = listener;
|
||||
}
|
||||
|
||||
|
||||
void submit(const JobResult &result)
|
||||
{
|
||||
uv_mutex_lock(&m_mutex);
|
||||
m_queue.push_back(result);
|
||||
uv_mutex_unlock(&m_mutex);
|
||||
|
||||
uv_async_send(m_async);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
static void onResult(uv_async_t *handle)
|
||||
{
|
||||
static_cast<JobResultsPrivate*>(handle->data)->submit();
|
||||
}
|
||||
|
||||
|
||||
inline void submit()
|
||||
{
|
||||
std::list<JobResult> results;
|
||||
|
||||
uv_mutex_lock(&m_mutex);
|
||||
while (!m_queue.empty()) {
|
||||
results.push_back(std::move(m_queue.front()));
|
||||
m_queue.pop_front();
|
||||
}
|
||||
uv_mutex_unlock(&m_mutex);
|
||||
|
||||
for (auto result : results) {
|
||||
m_listener->onJobResult(result);
|
||||
}
|
||||
|
||||
results.clear();
|
||||
}
|
||||
|
||||
|
||||
IJobResultListener *m_listener = nullptr;
|
||||
std::list<JobResult> m_queue;
|
||||
uv_async_t *m_async;
|
||||
uv_mutex_t m_mutex;
|
||||
};
|
||||
|
||||
|
||||
static JobResultsPrivate *handler = new JobResultsPrivate();
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
|
||||
void xmrig::JobResults::setListener(IJobResultListener *listener)
|
||||
{
|
||||
assert(handler != nullptr && listener != nullptr);
|
||||
|
||||
handler->setListener(listener);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::JobResults::stop()
|
||||
{
|
||||
delete handler;
|
||||
|
||||
handler = nullptr;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::JobResults::submit(const JobResult &result)
|
||||
{
|
||||
assert(handler != nullptr);
|
||||
|
||||
if (handler) {
|
||||
handler->submit(result);
|
||||
}
|
||||
}
|
49
src/net/JobResults.h
Normal file
49
src/net/JobResults.h
Normal file
@ -0,0 +1,49 @@
|
||||
/* 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 Lee Clagett <https://github.com/vtnerd>
|
||||
* 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_JOBRESULTS_H
|
||||
#define XMRIG_JOBRESULTS_H
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class IJobResultListener;
|
||||
class JobResult;
|
||||
|
||||
|
||||
class JobResults
|
||||
{
|
||||
public:
|
||||
static void setListener(IJobResultListener *listener);
|
||||
static void stop();
|
||||
static void submit(const JobResult &result);
|
||||
};
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif /* XMRIG_JOBRESULTS_H */
|
@ -40,6 +40,7 @@
|
||||
#include "base/tools/Timer.h"
|
||||
#include "core/config/Config.h"
|
||||
#include "core/Controller.h"
|
||||
#include "net/JobResults.h"
|
||||
#include "net/Network.h"
|
||||
#include "net/strategies/DonateStrategy.h"
|
||||
#include "rapidjson/document.h"
|
||||
@ -57,7 +58,7 @@ xmrig::Network::Network(Controller *controller) :
|
||||
m_donate(nullptr),
|
||||
m_timer(nullptr)
|
||||
{
|
||||
Workers::setListener(this);
|
||||
JobResults::setListener(this);
|
||||
controller->addListener(this);
|
||||
|
||||
# ifdef XMRIG_FEATURE_API
|
||||
@ -77,6 +78,8 @@ xmrig::Network::Network(Controller *controller) :
|
||||
|
||||
xmrig::Network::~Network()
|
||||
{
|
||||
JobResults::stop();
|
||||
|
||||
delete m_timer;
|
||||
|
||||
if (m_donate) {
|
||||
|
@ -28,6 +28,7 @@
|
||||
|
||||
|
||||
#include "crypto/cn/CryptoNight_test.h"
|
||||
#include "net/JobResults.h"
|
||||
#include "workers/CpuThreadLegacy.h"
|
||||
#include "workers/MultiWorker.h"
|
||||
#include "workers/Workers.h"
|
||||
@ -170,7 +171,7 @@ void xmrig::MultiWorker<N>::start()
|
||||
|
||||
for (size_t i = 0; i < N; ++i) {
|
||||
if (*reinterpret_cast<uint64_t*>(m_hash + (i * 32) + 24) < m_state.job.target()) {
|
||||
Workers::submit(JobResult(m_state.job.poolId(), m_state.job.id(), m_state.job.clientId(), *nonce(i), m_hash + (i * 32), m_state.job.diff(), m_state.job.algorithm()));
|
||||
JobResults::submit(JobResult(m_state.job.poolId(), m_state.job.id(), m_state.job.clientId(), *nonce(i), m_hash + (i * 32), m_state.job.diff(), m_state.job.algorithm()));
|
||||
}
|
||||
|
||||
*nonce(i) += 1;
|
||||
|
@ -32,7 +32,6 @@
|
||||
#include "base/tools/Handle.h"
|
||||
#include "core/config/Config.h"
|
||||
#include "core/Controller.h"
|
||||
#include "interfaces/IJobResultListener.h"
|
||||
#include "interfaces/IThread.h"
|
||||
#include "Mem.h"
|
||||
#include "rapidjson/document.h"
|
||||
@ -45,15 +44,12 @@
|
||||
bool Workers::m_active = false;
|
||||
bool Workers::m_enabled = true;
|
||||
Hashrate *Workers::m_hashrate = nullptr;
|
||||
xmrig::IJobResultListener *Workers::m_listener = nullptr;
|
||||
xmrig::Job Workers::m_job;
|
||||
Workers::LaunchStatus Workers::m_status;
|
||||
std::atomic<int> Workers::m_paused;
|
||||
std::atomic<uint64_t> Workers::m_sequence;
|
||||
std::list<xmrig::JobResult> Workers::m_queue;
|
||||
std::vector<ThreadHandle*> Workers::m_workers;
|
||||
uint64_t Workers::m_ticks = 0;
|
||||
uv_async_t *Workers::m_async = nullptr;
|
||||
uv_mutex_t Workers::m_mutex;
|
||||
uv_rwlock_t Workers::m_rwlock;
|
||||
uv_timer_t *Workers::m_timer = nullptr;
|
||||
@ -199,9 +195,6 @@ void Workers::start(xmrig::Controller *controller)
|
||||
m_sequence = 1;
|
||||
m_paused = 1;
|
||||
|
||||
m_async = new uv_async_t;
|
||||
uv_async_init(uv_default_loop(), m_async, Workers::onResult);
|
||||
|
||||
m_timer = new uv_timer_t;
|
||||
uv_timer_init(uv_default_loop(), m_timer);
|
||||
uv_timer_start(m_timer, Workers::onTick, 500, 500);
|
||||
@ -221,7 +214,6 @@ void Workers::start(xmrig::Controller *controller)
|
||||
void Workers::stop()
|
||||
{
|
||||
xmrig::Handle::close(m_timer);
|
||||
xmrig::Handle::close(m_async);
|
||||
m_hashrate->stop();
|
||||
|
||||
m_paused = 0;
|
||||
@ -233,16 +225,6 @@ void Workers::stop()
|
||||
}
|
||||
|
||||
|
||||
void Workers::submit(const xmrig::JobResult &result)
|
||||
{
|
||||
uv_mutex_lock(&m_mutex);
|
||||
m_queue.push_back(result);
|
||||
uv_mutex_unlock(&m_mutex);
|
||||
|
||||
uv_async_send(m_async);
|
||||
}
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_API
|
||||
void Workers::threadsSummary(rapidjson::Document &doc)
|
||||
{
|
||||
@ -306,25 +288,6 @@ void Workers::onReady(void *arg)
|
||||
}
|
||||
|
||||
|
||||
void Workers::onResult(uv_async_t *)
|
||||
{
|
||||
std::list<xmrig::JobResult> results;
|
||||
|
||||
uv_mutex_lock(&m_mutex);
|
||||
while (!m_queue.empty()) {
|
||||
results.push_back(std::move(m_queue.front()));
|
||||
m_queue.pop_front();
|
||||
}
|
||||
uv_mutex_unlock(&m_mutex);
|
||||
|
||||
for (auto result : results) {
|
||||
m_listener->onJobResult(result);
|
||||
}
|
||||
|
||||
results.clear();
|
||||
}
|
||||
|
||||
|
||||
void Workers::onTick(uv_timer_t *)
|
||||
{
|
||||
for (ThreadHandle *handle : m_workers) {
|
||||
|
@ -47,7 +47,6 @@ class ThreadHandle;
|
||||
|
||||
namespace xmrig {
|
||||
class Controller;
|
||||
class IJobResultListener;
|
||||
}
|
||||
|
||||
|
||||
@ -62,7 +61,6 @@ public:
|
||||
static void setJob(const xmrig::Job &job, bool donate);
|
||||
static void start(xmrig::Controller *controller);
|
||||
static void stop();
|
||||
static void submit(const xmrig::JobResult &result);
|
||||
|
||||
static inline bool isEnabled() { return m_enabled; }
|
||||
static inline bool isOutdated(uint64_t sequence) { return m_sequence.load(std::memory_order_relaxed) != sequence; }
|
||||
@ -70,7 +68,6 @@ public:
|
||||
static inline Hashrate *hashrate() { return m_hashrate; }
|
||||
static inline uint64_t sequence() { return m_sequence.load(std::memory_order_relaxed); }
|
||||
static inline void pause() { m_active = false; m_paused = 1; m_sequence++; }
|
||||
static inline void setListener(xmrig::IJobResultListener *listener) { m_listener = listener; }
|
||||
|
||||
# ifdef XMRIG_FEATURE_API
|
||||
static void threadsSummary(rapidjson::Document &doc);
|
||||
@ -83,7 +80,6 @@ public:
|
||||
|
||||
private:
|
||||
static void onReady(void *arg);
|
||||
static void onResult(uv_async_t *handle);
|
||||
static void onTick(uv_timer_t *handle);
|
||||
static void start(IWorker *worker);
|
||||
|
||||
@ -109,15 +105,12 @@ private:
|
||||
static bool m_active;
|
||||
static bool m_enabled;
|
||||
static Hashrate *m_hashrate;
|
||||
static xmrig::IJobResultListener *m_listener;
|
||||
static xmrig::Job m_job;
|
||||
static LaunchStatus m_status;
|
||||
static std::atomic<int> m_paused;
|
||||
static std::atomic<uint64_t> m_sequence;
|
||||
static std::list<xmrig::JobResult> m_queue;
|
||||
static std::vector<ThreadHandle*> m_workers;
|
||||
static uint64_t m_ticks;
|
||||
static uv_async_t *m_async;
|
||||
static uv_mutex_t m_mutex;
|
||||
static uv_rwlock_t m_rwlock;
|
||||
static uv_timer_t *m_timer;
|
||||
|
Reference in New Issue
Block a user