Files
xmrig/src/workers/Workers.h

123 lines
3.9 KiB
C
Raw Normal View History

2017-06-10 09:41:08 +03:00
/* 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>
2019-01-15 02:15:36 +07:00
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
2017-06-10 09:41:08 +03:00
*
* 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/>.
*/
2019-01-15 02:15:36 +07:00
#ifndef XMRIG_WORKERS_H
#define XMRIG_WORKERS_H
2017-06-10 09:41:08 +03:00
2017-06-11 06:52:23 +03:00
#include <atomic>
2017-06-11 10:58:46 +03:00
#include <list>
2017-06-10 09:41:08 +03:00
#include <uv.h>
2017-06-11 06:52:23 +03:00
#include <vector>
2018-04-20 23:44:32 +07:00
#include "common/net/Job.h"
2017-06-11 10:58:46 +03:00
#include "net/JobResult.h"
2018-04-17 14:36:32 +07:00
#include "rapidjson/fwd.h"
2017-06-10 09:41:08 +03:00
class Handle;
2017-06-15 21:00:25 +03:00
class Hashrate;
2017-06-11 15:32:15 +03:00
class IJobResultListener;
class IWorker;
2017-06-10 09:41:08 +03:00
namespace xmrig {
class Controller;
}
2017-06-10 09:41:08 +03:00
class Workers
{
public:
2017-06-11 06:52:23 +03:00
static Job job();
static size_t hugePages();
static size_t threads();
2017-07-23 09:36:30 +03:00
static void printHashrate(bool detail);
2017-07-10 21:42:28 +03:00
static void setEnabled(bool enabled);
static void setJob(const Job &job, bool donate);
2018-04-03 03:27:44 +07:00
static void start(xmrig::Controller *controller);
2017-07-18 05:20:36 +03:00
static void stop();
2017-06-11 10:58:46 +03:00
static void submit(const JobResult &result);
2017-06-10 09:41:08 +03:00
2017-07-10 21:42:28 +03:00
static inline bool isEnabled() { return m_enabled; }
2017-06-11 15:32:15 +03:00
static inline bool isOutdated(uint64_t sequence) { return m_sequence.load(std::memory_order_relaxed) != sequence; }
static inline bool isPaused() { return m_paused.load(std::memory_order_relaxed) == 1; }
2018-04-17 10:29:37 +07:00
static inline Hashrate *hashrate() { return m_hashrate; }
2017-06-11 15:32:15 +03:00
static inline uint64_t sequence() { return m_sequence.load(std::memory_order_relaxed); }
2017-07-10 21:42:28 +03:00
static inline void pause() { m_active = false; m_paused = 1; m_sequence++; }
2017-06-11 15:32:15 +03:00
static inline void setListener(IJobResultListener *listener) { m_listener = listener; }
2017-06-11 06:52:23 +03:00
2018-04-17 14:36:32 +07:00
# ifndef XMRIG_NO_API
static void threadsSummary(rapidjson::Document &doc);
# endif
2017-06-10 09:41:08 +03:00
private:
2017-06-12 16:19:07 +03:00
static void onReady(void *arg);
2017-06-10 09:41:08 +03:00
static void onResult(uv_async_t *handle);
2017-06-12 16:19:07 +03:00
static void onTick(uv_timer_t *handle);
static void start(IWorker *worker);
class LaunchStatus
{
public:
inline LaunchStatus() :
colors(true),
hugePages(0),
pages(0),
started(0),
threads(0),
ways(0),
algo(xmrig::CRYPTONIGHT)
{}
bool colors;
size_t hugePages;
size_t pages;
size_t started;
size_t threads;
size_t ways;
xmrig::Algo algo;
};
2017-06-10 09:41:08 +03:00
2017-07-10 21:42:28 +03:00
static bool m_active;
static bool m_enabled;
2017-06-15 21:00:25 +03:00
static Hashrate *m_hashrate;
2017-06-11 15:32:15 +03:00
static IJobResultListener *m_listener;
2017-06-11 06:52:23 +03:00
static Job m_job;
static LaunchStatus m_status;
2017-06-11 06:52:23 +03:00
static std::atomic<int> m_paused;
static std::atomic<uint64_t> m_sequence;
2017-06-11 10:58:46 +03:00
static std::list<JobResult> m_queue;
2017-06-10 09:41:08 +03:00
static std::vector<Handle*> m_workers;
2017-06-12 07:18:14 +03:00
static uint64_t m_ticks;
2017-06-10 09:41:08 +03:00
static uv_async_t m_async;
2017-06-12 16:19:07 +03:00
static uv_mutex_t m_mutex;
static uv_rwlock_t m_rwlock;
2017-06-12 07:18:14 +03:00
static uv_timer_t m_timer;
2018-06-01 02:33:21 +07:00
static xmrig::Controller *m_controller;
2017-06-10 09:41:08 +03:00
};
2019-01-15 02:15:36 +07:00
#endif /* XMRIG_WORKERS_H */