diff --git a/src/backend/common/Workers.cpp b/src/backend/common/Workers.cpp index 16265b0a5..e9416776e 100644 --- a/src/backend/common/Workers.cpp +++ b/src/backend/common/Workers.cpp @@ -1,13 +1,6 @@ /* XMRig - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * Copyright 2014 Lucas Jones - * Copyright 2014-2016 Wolf9466 - * Copyright 2016 Jay D Dee - * Copyright 2017-2018 XMR-Stak , - * Copyright 2018 Lee Clagett - * Copyright 2018-2020 SChernykh - * Copyright 2016-2020 XMRig , + * Copyright (c) 2018-2020 SChernykh + * Copyright (c) 2016-2020 XMRig , * * 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 @@ -24,16 +17,13 @@ */ +#include "backend/common/Workers.h" #include "backend/common/Hashrate.h" #include "backend/common/interfaces/IBackend.h" -#include "backend/common/Workers.h" #include "backend/cpu/CpuWorker.h" #include "base/io/log/Log.h" #include "base/io/log/Tags.h" -#include "base/net/stratum/Pool.h" #include "base/tools/Chrono.h" -#include "base/tools/Object.h" -#include "core/Miner.h" #ifdef XMRIG_FEATURE_OPENCL @@ -59,7 +49,6 @@ class WorkersPrivate public: XMRIG_DISABLE_COPY_MOVE(WorkersPrivate) - WorkersPrivate() = default; ~WorkersPrivate() = default; @@ -69,6 +58,20 @@ public: }; +template +inline static void getHashrateData(IWorker *worker, uint64_t &hashCount, uint64_t &timeStamp) +{ + worker->getHashrateData(hashCount, timeStamp); +} + + +template<> +inline void getHashrateData(IWorker *worker, uint64_t &hashCount, uint64_t &) +{ + hashCount = worker->rawHashes(); +} + + } // namespace xmrig @@ -87,20 +90,6 @@ xmrig::Workers::~Workers() } -template -static void getHashrateData(xmrig::IWorker* worker, uint64_t& hashCount, uint64_t& timeStamp) -{ - worker->getHashrateData(hashCount, timeStamp); -} - - -template<> -void getHashrateData(xmrig::IWorker* worker, uint64_t& hashCount, uint64_t&) -{ - hashCount = worker->rawHashes(); -} - - template bool xmrig::Workers::tick(uint64_t) { @@ -132,12 +121,10 @@ bool xmrig::Workers::tick(uint64_t) } # ifdef XMRIG_FEATURE_BENCHMARK - if (d_ptr->benchmark && d_ptr->benchmark->finish(totalHashCount)) { - return false; - } -# endif - + return !d_ptr->benchmark || !d_ptr->benchmark->finish(totalHashCount); +# else return true; +# endif } @@ -158,14 +145,19 @@ void xmrig::Workers::setBackend(IBackend *backend) template void xmrig::Workers::stop() { +# ifdef XMRIG_MINER_PROJECT Nonce::stop(T::backend()); +# endif for (Thread *worker : m_workers) { delete worker; } m_workers.clear(); + +# ifdef XMRIG_MINER_PROJECT Nonce::touch(T::backend()); +# endif d_ptr->hashrate.reset(); } @@ -226,7 +218,10 @@ void xmrig::Workers::start(const std::vector &data, bool sleep) } d_ptr->hashrate = std::make_shared(m_workers.size()); + +# ifdef XMRIG_MINER_PROJECT Nonce::touch(T::backend()); +# endif for (auto worker : m_workers) { worker->start(Workers::onReady); @@ -247,6 +242,7 @@ namespace xmrig { template<> xmrig::IWorker *xmrig::Workers::create(Thread *handle) { +# ifdef XMRIG_MINER_PROJECT switch (handle->config().intensity) { case 1: return new CpuWorker<1>(handle->id(), handle->config()); @@ -265,6 +261,11 @@ xmrig::IWorker *xmrig::Workers::create(Thread *han } return nullptr; +# else + assert(handle->config().intensity == 1); + + return new CpuWorker<1>(handle->id(), handle->config()); +# endif } diff --git a/src/backend/common/Workers.h b/src/backend/common/Workers.h index 5cdc78a2e..1313384cc 100644 --- a/src/backend/common/Workers.h +++ b/src/backend/common/Workers.h @@ -1,13 +1,6 @@ /* XMRig - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * Copyright 2014 Lucas Jones - * Copyright 2014-2016 Wolf9466 - * Copyright 2016 Jay D Dee - * Copyright 2017-2018 XMR-Stak , - * Copyright 2018 Lee Clagett - * Copyright 2018-2020 SChernykh - * Copyright 2016-2020 XMRig , + * Copyright (c) 2018-2020 SChernykh + * Copyright (c) 2016-2020 XMRig , * * 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 @@ -44,10 +37,9 @@ namespace xmrig { +class Benchmark; class Hashrate; class WorkersPrivate; -class Job; -class Benchmark; template @@ -63,7 +55,7 @@ public: bool tick(uint64_t ticks); const Hashrate *hashrate() const; - void jobEarlyNotification(const Job&); + void jobEarlyNotification(const Job &job); void setBackend(IBackend *backend); void stop(); @@ -83,7 +75,7 @@ private: template -void xmrig::Workers::jobEarlyNotification(const Job& job) +void xmrig::Workers::jobEarlyNotification(const Job &job) { for (Thread* t : m_workers) { if (t->worker()) { diff --git a/src/backend/common/interfaces/IBackend.h b/src/backend/common/interfaces/IBackend.h index c07ee49a9..53e8e0f12 100644 --- a/src/backend/common/interfaces/IBackend.h +++ b/src/backend/common/interfaces/IBackend.h @@ -1,12 +1,6 @@ /* XMRig - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * Copyright 2014 Lucas Jones - * Copyright 2014-2016 Wolf9466 - * Copyright 2016 Jay D Dee - * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2020 SChernykh - * Copyright 2016-2020 XMRig , + * Copyright (c) 2018-2020 SChernykh + * Copyright (c) 2016-2020 XMRig , * * 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 @@ -26,10 +20,11 @@ #define XMRIG_IBACKEND_H -#include - - #include "3rdparty/rapidjson/fwd.h" +#include "base/tools/Object.h" + + +#include namespace xmrig { @@ -47,10 +42,14 @@ class String; class IBackend { public: + XMRIG_DISABLE_COPY_MOVE(IBackend) + + IBackend() = default; virtual ~IBackend() = default; virtual bool isEnabled() const = 0; virtual bool isEnabled(const Algorithm &algorithm) const = 0; + virtual bool tick(uint64_t ticks) = 0; virtual const Hashrate *hashrate() const = 0; virtual const String &profileName() const = 0; virtual const String &type() const = 0; @@ -61,7 +60,6 @@ public: virtual void setJob(const Job &job) = 0; virtual void start(IWorker *worker, bool ready) = 0; virtual void stop() = 0; - virtual bool tick(uint64_t ticks) = 0; # ifdef XMRIG_FEATURE_API virtual rapidjson::Value toJSON(rapidjson::Document &doc) const = 0; diff --git a/src/backend/common/interfaces/IMemoryPool.h b/src/backend/common/interfaces/IMemoryPool.h index 44ff2495c..10d27b504 100644 --- a/src/backend/common/interfaces/IMemoryPool.h +++ b/src/backend/common/interfaces/IMemoryPool.h @@ -1,14 +1,6 @@ /* XMRig - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * Copyright 2014 Lucas Jones - * Copyright 2014-2016 Wolf9466 - * Copyright 2016 Jay D Dee - * Copyright 2017-2018 XMR-Stak , - * Copyright 2018 Lee Clagett - * Copyright 2018-2019 SChernykh - * Copyright 2018-2019 tevador - * Copyright 2016-2019 XMRig , + * Copyright (c) 2018-2020 SChernykh + * Copyright (c) 2016-2020 XMRig , * * 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 @@ -28,6 +20,9 @@ #define XMRIG_IMEMORYPOOL_H +#include "base/tools/Object.h" + + #include #include @@ -38,7 +33,10 @@ namespace xmrig { class IMemoryPool { public: - virtual ~IMemoryPool() = default; + XMRIG_DISABLE_COPY_MOVE(IMemoryPool) + + IMemoryPool() = default; + virtual ~IMemoryPool() = default; virtual bool isHugePages(uint32_t node) const = 0; virtual uint8_t *get(size_t size, uint32_t node) = 0; diff --git a/src/backend/common/interfaces/IRxListener.h b/src/backend/common/interfaces/IRxListener.h index b4dde9e5a..11adb0d4f 100644 --- a/src/backend/common/interfaces/IRxListener.h +++ b/src/backend/common/interfaces/IRxListener.h @@ -1,10 +1,7 @@ /* XMRig - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * Copyright 2014 Lucas Jones - * Copyright 2014-2016 Wolf9466 - * Copyright 2016 Jay D Dee - * Copyright 2016-2018 XMRig + * Copyright (c) 2018-2019 tevador + * Copyright (c) 2018-2020 SChernykh + * Copyright (c) 2016-2020 XMRig , * * 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 @@ -24,13 +21,19 @@ #define XMRIG_IRXLISTENER_H +#include "base/tools/Object.h" + + namespace xmrig { class IRxListener { public: - virtual ~IRxListener() = default; + XMRIG_DISABLE_COPY_MOVE(IRxListener) + + IRxListener() = default; + virtual ~IRxListener() = default; # ifdef XMRIG_ALGO_RANDOMX virtual void onDatasetReady() = 0; diff --git a/src/backend/common/interfaces/IWorker.h b/src/backend/common/interfaces/IWorker.h index f528469a5..114f545de 100644 --- a/src/backend/common/interfaces/IWorker.h +++ b/src/backend/common/interfaces/IWorker.h @@ -1,12 +1,6 @@ /* XMRig - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * Copyright 2014 Lucas Jones - * Copyright 2014-2016 Wolf9466 - * Copyright 2016 Jay D Dee - * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2020 SChernykh - * Copyright 2016-2020 XMRig , + * Copyright (c) 2018-2020 SChernykh + * Copyright (c) 2016-2020 XMRig , * * 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 @@ -36,8 +30,8 @@ namespace xmrig { -class VirtualMemory; class Job; +class VirtualMemory; class IWorker @@ -48,14 +42,14 @@ public: IWorker() = default; virtual ~IWorker() = default; - virtual bool selfTest() = 0; - virtual const VirtualMemory *memory() const = 0; - virtual size_t id() const = 0; - virtual size_t intensity() const = 0; - virtual uint64_t rawHashes() const = 0; - virtual void getHashrateData(uint64_t&, uint64_t&) const = 0; - virtual void start() = 0; - virtual void jobEarlyNotification(const Job&) = 0; + virtual bool selfTest() = 0; + virtual const VirtualMemory *memory() const = 0; + virtual size_t id() const = 0; + virtual size_t intensity() const = 0; + virtual uint64_t rawHashes() const = 0; + virtual void getHashrateData(uint64_t &hashCount, uint64_t &timeStamp) const = 0; + virtual void jobEarlyNotification(const Job &job) = 0; + virtual void start() = 0; }; diff --git a/src/backend/cpu/CpuBackend.cpp b/src/backend/cpu/CpuBackend.cpp index fc6b7e74a..07df88173 100644 --- a/src/backend/cpu/CpuBackend.cpp +++ b/src/backend/cpu/CpuBackend.cpp @@ -266,6 +266,12 @@ bool xmrig::CpuBackend::isEnabled(const Algorithm &algorithm) const } +bool xmrig::CpuBackend::tick(uint64_t ticks) +{ + return d_ptr->workers.tick(ticks); +} + + const xmrig::Hashrate *xmrig::CpuBackend::hashrate() const { return d_ptr->workers.hashrate(); @@ -405,12 +411,6 @@ void xmrig::CpuBackend::stop() } -bool xmrig::CpuBackend::tick(uint64_t ticks) -{ - return d_ptr->workers.tick(ticks); -} - - #ifdef XMRIG_FEATURE_API rapidjson::Value xmrig::CpuBackend::toJSON(rapidjson::Document &doc) const { diff --git a/src/backend/cpu/CpuBackend.h b/src/backend/cpu/CpuBackend.h index 5be933c39..2f697b8bd 100644 --- a/src/backend/cpu/CpuBackend.h +++ b/src/backend/cpu/CpuBackend.h @@ -54,6 +54,7 @@ protected: bool isEnabled() const override; bool isEnabled(const Algorithm &algorithm) const override; + bool tick(uint64_t ticks) override; const Hashrate *hashrate() const override; const String &profileName() const override; const String &type() const override; @@ -63,7 +64,6 @@ protected: void setJob(const Job &job) override; void start(IWorker *worker, bool ready) override; void stop() override; - bool tick(uint64_t ticks) override; # ifdef XMRIG_FEATURE_API rapidjson::Value toJSON(rapidjson::Document &doc) const override;