#40 Fix crash on Linux.

This commit is contained in:
XMRig 2017-07-19 04:28:59 +03:00
parent ebf54c6d04
commit 8f38462bbe
8 changed files with 21 additions and 8 deletions

View file

@ -123,10 +123,10 @@ int App::exec()
void App::close() void App::close()
{ {
uv_signal_stop(&m_signal);
m_network->stop(); m_network->stop();
Workers::stop(); Workers::stop();
uv_stop(uv_default_loop());
} }
@ -150,5 +150,6 @@ void App::onSignal(uv_signal_t *handle, int signum)
break; break;
} }
uv_signal_stop(handle);
m_self->close(); m_self->close();
} }

View file

@ -127,7 +127,7 @@ void Network::onPause(IStrategy *strategy)
} }
if (!m_strategy->isActive()) { if (!m_strategy->isActive()) {
LOG_ERR("no active pools, pause mining"); LOG_ERR("no active pools, stop mining");
return Workers::pause(); return Workers::pause();
} }
} }

View file

@ -62,7 +62,7 @@ DoubleWorker::~DoubleWorker()
void DoubleWorker::start() void DoubleWorker::start()
{ {
while (true) { while (Workers::sequence() > 0) {
if (Workers::isPaused()) { if (Workers::isPaused()) {
do { do {
std::this_thread::sleep_for(std::chrono::milliseconds(200)); std::this_thread::sleep_for(std::chrono::milliseconds(200));

View file

@ -34,6 +34,12 @@ Handle::Handle(int threadId, int threads, int64_t affinity) :
} }
void Handle::join()
{
uv_thread_join(&m_thread);
}
void Handle::start(void (*callback) (void *)) void Handle::start(void (*callback) (void *))
{ {
uv_thread_create(&m_thread, callback, this); uv_thread_create(&m_thread, callback, this);

View file

@ -36,6 +36,7 @@ class Handle
{ {
public: public:
Handle(int threadId, int threads, int64_t affinity); Handle(int threadId, int threads, int64_t affinity);
void join();
void start(void (*callback) (void *)); void start(void (*callback) (void *));
inline int threadId() const { return m_threadId; } inline int threadId() const { return m_threadId; }

View file

@ -38,7 +38,7 @@ SingleWorker::SingleWorker(Handle *handle)
void SingleWorker::start() void SingleWorker::start()
{ {
while (true) { while (Workers::sequence() > 0) {
if (Workers::isPaused()) { if (Workers::isPaused()) {
do { do {
std::this_thread::sleep_for(std::chrono::milliseconds(200)); std::this_thread::sleep_for(std::chrono::milliseconds(200));

View file

@ -100,7 +100,7 @@ void Workers::start(int64_t affinity)
uv_mutex_init(&m_mutex); uv_mutex_init(&m_mutex);
uv_rwlock_init(&m_rwlock); uv_rwlock_init(&m_rwlock);
m_sequence = 0; m_sequence = 1;
m_paused = 1; m_paused = 1;
uv_async_init(uv_default_loop(), &m_async, Workers::onResult); uv_async_init(uv_default_loop(), &m_async, Workers::onResult);
@ -121,6 +121,11 @@ void Workers::stop()
m_hashrate->stop(); m_hashrate->stop();
uv_close(reinterpret_cast<uv_handle_t*>(&m_async), nullptr); uv_close(reinterpret_cast<uv_handle_t*>(&m_async), nullptr);
m_sequence = 0;
for (size_t i = 0; i < m_workers.size(); ++i) {
m_workers[i]->join();
}
} }

View file

@ -25,7 +25,7 @@
int main(int argc, char **argv) { int main(int argc, char **argv) {
auto app = new App(argc, argv); App app(argc, argv);
return app->exec(); return app.exec();
} }