Allow partially started threads.

This commit is contained in:
XMRig 2019-09-17 02:22:59 +07:00
parent e8acb8a2a9
commit e3fcb99d84
14 changed files with 94 additions and 37 deletions

View file

@ -26,10 +26,11 @@
#define XMRIG_THREAD_H
#include <thread>
#include "backend/common/interfaces/IWorker.h"
#include "base/tools/Object.h"
#include <thread>
namespace xmrig {
@ -42,6 +43,8 @@ template<class T>
class Thread
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Thread)
inline Thread(IBackend *backend, size_t id, const T &config) : m_id(id), m_config(config), m_backend(backend) {}
inline ~Thread() { m_thread.join(); delete m_worker; }

View file

@ -133,7 +133,7 @@ void xmrig::Workers<T>::tick(uint64_t)
for (Thread<T> *handle : m_workers) {
if (!handle->worker()) {
return;
continue;
}
d_ptr->hashrate->add(handle->id(), handle->worker()->hashCount(), handle->worker()->timestamp());
@ -156,17 +156,21 @@ void xmrig::Workers<T>::onReady(void *arg)
auto handle = static_cast<Thread<T>* >(arg);
IWorker *worker = create(handle);
assert(worker != nullptr);
if (!worker || !worker->selfTest()) {
LOG_ERR("%s " RED("thread ") RED_BOLD("#%zu") RED(" self-test failed"), T::tag(), worker->id());
handle->backend()->start(worker, false);
delete worker;
return;
}
assert(handle->backend() != nullptr);
handle->setWorker(worker);
handle->backend()->start(worker);
handle->backend()->start(worker, true);
}

View file

@ -29,6 +29,7 @@
#include "backend/common/Thread.h"
#include "backend/cpu/CpuLaunchData.h"
#include "base/tools/Object.h"
#ifdef XMRIG_FEATURE_OPENCL
@ -47,6 +48,8 @@ template<class T>
class Workers
{
public:
XMRIG_DISABLE_COPY_MOVE(Workers)
Workers();
~Workers();

View file

@ -56,7 +56,7 @@ public:
virtual void prepare(const Job &nextJob) = 0;
virtual void printHashrate(bool details) = 0;
virtual void setJob(const Job &job) = 0;
virtual void start(IWorker *worker) = 0;
virtual void start(IWorker *worker, bool ready) = 0;
virtual void stop() = 0;
virtual void tick(uint64_t ticks) = 0;

View file

@ -26,8 +26,8 @@
#define XMRIG_IWORKER_H
#include <stdint.h>
#include <stddef.h>
#include <cstdint>
#include <cstddef>
namespace xmrig {
@ -44,6 +44,7 @@ public:
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 hashCount() const = 0;
virtual uint64_t timestamp() const = 0;
virtual void start() = 0;