xmrig/src/workers/Workers.h

78 lines
2.6 KiB
C
Raw Normal View History

2017-06-10 06:41:08 +00: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 2016-2017 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 __WORKERS_H__
#define __WORKERS_H__
2017-06-11 03:52:23 +00:00
#include <atomic>
2017-06-11 07:58:46 +00:00
#include <list>
2017-06-11 03:52:23 +00:00
#include <pthread.h>
2017-06-10 06:41:08 +00:00
#include <uv.h>
2017-06-11 03:52:23 +00:00
#include <vector>
#include "net/Job.h"
2017-06-11 07:58:46 +00:00
#include "net/JobResult.h"
2017-06-10 06:41:08 +00:00
class Handle;
2017-06-11 12:32:15 +00:00
class IJobResultListener;
2017-06-12 04:18:14 +00:00
class Telemetry;
2017-06-10 06:41:08 +00:00
class Workers
{
public:
2017-06-11 03:52:23 +00:00
static Job job();
static void setJob(const Job &job);
static void start(int threads, int64_t affinity, bool nicehash);
2017-06-11 07:58:46 +00:00
static void submit(const JobResult &result);
2017-06-10 06:41:08 +00:00
2017-06-11 12:32:15 +00: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; }
static inline uint64_t sequence() { return m_sequence.load(std::memory_order_relaxed); }
static inline void pause() { m_paused = 1; }
static inline void setListener(IJobResultListener *listener) { m_listener = listener; }
2017-06-11 03:52:23 +00:00
2017-06-10 06:41:08 +00:00
private:
static void *onReady(void *arg);
2017-06-12 04:18:14 +00:00
static void onPerfTick(uv_timer_t *handle);
2017-06-10 06:41:08 +00:00
static void onResult(uv_async_t *handle);
2017-06-11 12:32:15 +00:00
static IJobResultListener *m_listener;
2017-06-11 03:52:23 +00:00
static Job m_job;
2017-06-11 07:58:46 +00:00
static pthread_mutex_t m_mutex;
2017-06-11 03:52:23 +00:00
static pthread_rwlock_t m_rwlock;
static std::atomic<int> m_paused;
static std::atomic<uint64_t> m_sequence;
2017-06-11 07:58:46 +00:00
static std::list<JobResult> m_queue;
2017-06-10 06:41:08 +00:00
static std::vector<Handle*> m_workers;
2017-06-12 04:18:14 +00:00
static Telemetry *m_telemetry;
static uint64_t m_ticks;
2017-06-10 06:41:08 +00:00
static uv_async_t m_async;
2017-06-12 04:18:14 +00:00
static uv_timer_t m_timer;
2017-06-10 06:41:08 +00:00
};
#endif /* __WORKERS_H__ */