Removed CPU specific code from Worker class.

This commit is contained in:
XMRig 2019-07-14 00:35:38 +07:00
parent ee434a5708
commit dff59fabc2
7 changed files with 39 additions and 44 deletions

View file

@ -23,36 +23,25 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <chrono>
#include "backend/common/Worker.h"
#include "backend/cpu/Cpu.h"
#include "base/kernel/Platform.h"
#include "workers/CpuThreadLegacy.h"
#include "workers/ThreadHandle.h"
#include "base/tools/Chrono.h"
Worker::Worker(ThreadHandle *handle) :
m_id(handle->threadId()),
xmrig::Worker::Worker(size_t id, int64_t affinity, int priority) :
m_id(id),
m_hashCount(0),
m_timestamp(0),
m_count(0),
m_thread(static_cast<xmrig::CpuThreadLegacy *>(handle->config()))
m_count(0)
{
if (xmrig::Cpu::info()->threads() > 1 && m_thread->affinity() != -1L) {
Platform::setThreadAffinity(m_thread->affinity());
}
Platform::setThreadPriority(m_thread->priority());
Platform::trySetThreadAffinity(affinity);
Platform::setThreadPriority(priority);
}
void Worker::storeStats()
void xmrig::Worker::storeStats()
{
using namespace std::chrono;
const uint64_t timestamp = time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count();
m_hashCount.store(m_count, std::memory_order_relaxed);
m_timestamp.store(timestamp, std::memory_order_relaxed);
m_timestamp.store(Chrono::highResolutionMSecs(), std::memory_order_relaxed);
}

View file

@ -32,23 +32,16 @@
#include "backend/common/interfaces/IWorker.h"
#include "Mem.h"
class ThreadHandle;
namespace xmrig {
class CpuThreadLegacy;
}
class Worker : public IWorker
{
public:
Worker(ThreadHandle *handle);
Worker(size_t id, int64_t affinity, int priority);
inline const MemInfo &memory() const { return m_memory; }
inline size_t id() const override { return m_id; }
inline uint64_t hashCount() const override { return m_hashCount.load(std::memory_order_relaxed); }
inline uint64_t timestamp() const override { return m_timestamp.load(std::memory_order_relaxed); }
@ -57,12 +50,13 @@ protected:
void storeStats();
const size_t m_id;
MemInfo m_memory;
std::atomic<uint64_t> m_hashCount;
std::atomic<uint64_t> m_timestamp;
uint64_t m_count;
xmrig::CpuThreadLegacy *m_thread;
};
} // namespace xmrig
#endif /* XMRIG_WORKER_H */