Initial MSVC support.
This commit is contained in:
parent
a370b8fd30
commit
3df545cfc5
21 changed files with 845 additions and 96 deletions
|
@ -35,7 +35,7 @@ Handle::Handle(int threadId, int threads, int64_t affinity, bool nicehash) :
|
|||
}
|
||||
|
||||
|
||||
void Handle::start(void *(*callback) (void *))
|
||||
void Handle::start(void (*callback) (void *))
|
||||
{
|
||||
pthread_create(&m_thread, nullptr, callback, this);
|
||||
uv_thread_create(&m_thread, callback, this);
|
||||
}
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
#define __HANDLE_H__
|
||||
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdint.h>
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
class IWorker;
|
||||
|
@ -36,7 +36,7 @@ class Handle
|
|||
{
|
||||
public:
|
||||
Handle(int threadId, int threads, int64_t affinity, bool nicehash);
|
||||
void start(void *(*callback) (void *));
|
||||
void start(void (*callback) (void *));
|
||||
|
||||
inline bool nicehash() const { return m_nicehash; }
|
||||
inline int threadId() const { return m_threadId; }
|
||||
|
@ -51,7 +51,7 @@ private:
|
|||
int m_threads;
|
||||
int64_t m_affinity;
|
||||
IWorker *m_worker;
|
||||
pthread_t m_thread;
|
||||
uv_thread_t m_thread;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -22,11 +22,9 @@
|
|||
*/
|
||||
|
||||
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
|
||||
|
||||
#include "Console.h"
|
||||
#include "crypto/CryptoNight.h"
|
||||
#include "workers/SingleWorker.h"
|
||||
#include "workers/Workers.h"
|
||||
|
@ -62,7 +60,7 @@ void SingleWorker::start()
|
|||
Workers::submit(m_result);
|
||||
}
|
||||
|
||||
sched_yield();
|
||||
// sched_yield();
|
||||
}
|
||||
|
||||
consumeJob();
|
||||
|
|
|
@ -34,8 +34,6 @@
|
|||
|
||||
IJobResultListener *Workers::m_listener = nullptr;
|
||||
Job Workers::m_job;
|
||||
pthread_mutex_t Workers::m_mutex;
|
||||
pthread_rwlock_t Workers::m_rwlock;
|
||||
std::atomic<int> Workers::m_paused;
|
||||
std::atomic<uint64_t> Workers::m_sequence;
|
||||
std::list<JobResult> Workers::m_queue;
|
||||
|
@ -43,14 +41,16 @@ std::vector<Handle*> Workers::m_workers;
|
|||
Telemetry *Workers::m_telemetry = nullptr;
|
||||
uint64_t Workers::m_ticks = 0;
|
||||
uv_async_t Workers::m_async;
|
||||
uv_mutex_t Workers::m_mutex;
|
||||
uv_rwlock_t Workers::m_rwlock;
|
||||
uv_timer_t Workers::m_timer;
|
||||
|
||||
|
||||
Job Workers::job()
|
||||
{
|
||||
pthread_rwlock_rdlock(&m_rwlock);
|
||||
uv_rwlock_rdlock(&m_rwlock);
|
||||
Job job = m_job;
|
||||
pthread_rwlock_unlock(&m_rwlock);
|
||||
uv_rwlock_rdunlock(&m_rwlock);
|
||||
|
||||
return std::move(job);
|
||||
}
|
||||
|
@ -58,9 +58,9 @@ Job Workers::job()
|
|||
|
||||
void Workers::setJob(const Job &job)
|
||||
{
|
||||
pthread_rwlock_wrlock(&m_rwlock);
|
||||
uv_rwlock_wrlock(&m_rwlock);
|
||||
m_job = job;
|
||||
pthread_rwlock_unlock(&m_rwlock);
|
||||
uv_rwlock_wrunlock(&m_rwlock);
|
||||
|
||||
m_sequence++;
|
||||
m_paused = 0;
|
||||
|
@ -71,15 +71,15 @@ void Workers::start(int threads, int64_t affinity, bool nicehash)
|
|||
{
|
||||
m_telemetry = new Telemetry(threads);
|
||||
|
||||
pthread_mutex_init(&m_mutex, nullptr);
|
||||
pthread_rwlock_init(&m_rwlock, nullptr);
|
||||
uv_mutex_init(&m_mutex);
|
||||
uv_rwlock_init(&m_rwlock);
|
||||
|
||||
m_sequence = 0;
|
||||
m_paused = 1;
|
||||
|
||||
uv_async_init(uv_default_loop(), &m_async, Workers::onResult);
|
||||
uv_timer_init(uv_default_loop(), &m_timer);
|
||||
uv_timer_start(&m_timer, Workers::onPerfTick, 500, 500);
|
||||
uv_timer_start(&m_timer, Workers::onTick, 500, 500);
|
||||
|
||||
for (int i = 0; i < threads; ++i) {
|
||||
Handle *handle = new Handle(i, threads, affinity, nicehash);
|
||||
|
@ -91,26 +91,43 @@ void Workers::start(int threads, int64_t affinity, bool nicehash)
|
|||
|
||||
void Workers::submit(const JobResult &result)
|
||||
{
|
||||
pthread_mutex_lock(&m_mutex);
|
||||
uv_mutex_lock(&m_mutex);
|
||||
m_queue.push_back(result);
|
||||
pthread_mutex_unlock(&m_mutex);
|
||||
uv_mutex_unlock(&m_mutex);
|
||||
|
||||
uv_async_send(&m_async);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void *Workers::onReady(void *arg)
|
||||
void Workers::onReady(void *arg)
|
||||
{
|
||||
auto handle = static_cast<Handle*>(arg);
|
||||
IWorker *worker = new SingleWorker(handle);
|
||||
worker->start();
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
void Workers::onPerfTick(uv_timer_t *handle)
|
||||
void Workers::onResult(uv_async_t *handle)
|
||||
{
|
||||
std::list<JobResult> results;
|
||||
|
||||
uv_mutex_lock(&m_mutex);
|
||||
while (!m_queue.empty()) {
|
||||
results.push_back(std::move(m_queue.front()));
|
||||
m_queue.pop_front();
|
||||
}
|
||||
uv_mutex_unlock(&m_mutex);
|
||||
|
||||
for (auto result : results) {
|
||||
m_listener->onJobResult(result);
|
||||
}
|
||||
|
||||
results.clear();
|
||||
}
|
||||
|
||||
|
||||
void Workers::onTick(uv_timer_t *handle)
|
||||
{
|
||||
for (Handle *handle : m_workers) {
|
||||
m_telemetry->add(handle->threadId(), handle->worker()->hashCount(), handle->worker()->timestamp());
|
||||
|
@ -137,22 +154,3 @@ void Workers::onPerfTick(uv_timer_t *handle)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Workers::onResult(uv_async_t *handle)
|
||||
{
|
||||
std::list<JobResult> results;
|
||||
|
||||
pthread_mutex_lock(&m_mutex);
|
||||
while (!m_queue.empty()) {
|
||||
results.push_back(std::move(m_queue.front()));
|
||||
m_queue.pop_front();
|
||||
}
|
||||
pthread_mutex_unlock(&m_mutex);
|
||||
|
||||
for (auto result : results) {
|
||||
m_listener->onJobResult(result);
|
||||
}
|
||||
|
||||
results.clear();
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
|
||||
#include <atomic>
|
||||
#include <list>
|
||||
#include <pthread.h>
|
||||
#include <uv.h>
|
||||
#include <vector>
|
||||
|
||||
|
@ -55,14 +54,12 @@ public:
|
|||
static inline void setListener(IJobResultListener *listener) { m_listener = listener; }
|
||||
|
||||
private:
|
||||
static void *onReady(void *arg);
|
||||
static void onPerfTick(uv_timer_t *handle);
|
||||
static void onReady(void *arg);
|
||||
static void onResult(uv_async_t *handle);
|
||||
static void onTick(uv_timer_t *handle);
|
||||
|
||||
static IJobResultListener *m_listener;
|
||||
static Job m_job;
|
||||
static pthread_mutex_t m_mutex;
|
||||
static pthread_rwlock_t m_rwlock;
|
||||
static std::atomic<int> m_paused;
|
||||
static std::atomic<uint64_t> m_sequence;
|
||||
static std::list<JobResult> m_queue;
|
||||
|
@ -70,6 +67,8 @@ private:
|
|||
static Telemetry *m_telemetry;
|
||||
static uint64_t m_ticks;
|
||||
static uv_async_t m_async;
|
||||
static uv_mutex_t m_mutex;
|
||||
static uv_rwlock_t m_rwlock;
|
||||
static uv_timer_t m_timer;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue