xmrig/src/workers/Workers.h

82 lines
2.8 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-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-15 18:00:25 +00:00
class Hashrate;
2017-06-11 12:32:15 +00:00
class IJobResultListener;
2017-06-10 06:41:08 +00:00
class Workers
{
public:
2017-06-11 03:52:23 +00:00
static Job job();
2017-07-10 18:42:28 +00:00
static void setEnabled(bool enabled);
2017-06-11 03:52:23 +00:00
static void setJob(const Job &job);
static void start(int64_t affinity);
2017-07-18 02:20:36 +00:00
static void stop();
2017-06-11 07:58:46 +00:00
static void submit(const JobResult &result);
2017-06-10 06:41:08 +00:00
2017-07-10 18:42:28 +00:00
static inline bool isEnabled() { return m_enabled; }
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); }
2017-07-10 18:42:28 +00:00
static inline void pause() { m_active = false; m_paused = 1; m_sequence++; }
2017-06-11 12:32:15 +00:00
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:
2017-06-12 13:19:07 +00:00
static void onReady(void *arg);
2017-06-10 06:41:08 +00:00
static void onResult(uv_async_t *handle);
2017-06-12 13:19:07 +00:00
static void onTick(uv_timer_t *handle);
2017-06-10 06:41:08 +00:00
2017-07-10 18:42:28 +00:00
static bool m_active;
static bool m_enabled;
2017-06-15 18:00:25 +00:00
static Hashrate *m_hashrate;
2017-06-11 12:32:15 +00:00
static IJobResultListener *m_listener;
2017-06-11 03:52:23 +00:00
static Job m_job;
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 uint64_t m_ticks;
2017-06-10 06:41:08 +00:00
static uv_async_t m_async;
2017-06-12 13:19:07 +00:00
static uv_mutex_t m_mutex;
static uv_rwlock_t m_rwlock;
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__ */