mirror of
https://github.com/xmrig/xmrig.git
synced 2024-11-17 08:17:40 +00:00
#40 Fix crash on Linux.
This commit is contained in:
parent
ebf54c6d04
commit
8f38462bbe
8 changed files with 21 additions and 8 deletions
|
@ -123,10 +123,10 @@ int App::exec()
|
|||
|
||||
void App::close()
|
||||
{
|
||||
uv_signal_stop(&m_signal);
|
||||
|
||||
m_network->stop();
|
||||
Workers::stop();
|
||||
|
||||
uv_stop(uv_default_loop());
|
||||
}
|
||||
|
||||
|
||||
|
@ -150,5 +150,6 @@ void App::onSignal(uv_signal_t *handle, int signum)
|
|||
break;
|
||||
}
|
||||
|
||||
uv_signal_stop(handle);
|
||||
m_self->close();
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ void Network::onPause(IStrategy *strategy)
|
|||
}
|
||||
|
||||
if (!m_strategy->isActive()) {
|
||||
LOG_ERR("no active pools, pause mining");
|
||||
LOG_ERR("no active pools, stop mining");
|
||||
return Workers::pause();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ DoubleWorker::~DoubleWorker()
|
|||
|
||||
void DoubleWorker::start()
|
||||
{
|
||||
while (true) {
|
||||
while (Workers::sequence() > 0) {
|
||||
if (Workers::isPaused()) {
|
||||
do {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
|
|
|
@ -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 *))
|
||||
{
|
||||
uv_thread_create(&m_thread, callback, this);
|
||||
|
|
|
@ -36,6 +36,7 @@ class Handle
|
|||
{
|
||||
public:
|
||||
Handle(int threadId, int threads, int64_t affinity);
|
||||
void join();
|
||||
void start(void (*callback) (void *));
|
||||
|
||||
inline int threadId() const { return m_threadId; }
|
||||
|
|
|
@ -38,7 +38,7 @@ SingleWorker::SingleWorker(Handle *handle)
|
|||
|
||||
void SingleWorker::start()
|
||||
{
|
||||
while (true) {
|
||||
while (Workers::sequence() > 0) {
|
||||
if (Workers::isPaused()) {
|
||||
do {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
|
|
|
@ -100,7 +100,7 @@ void Workers::start(int64_t affinity)
|
|||
uv_mutex_init(&m_mutex);
|
||||
uv_rwlock_init(&m_rwlock);
|
||||
|
||||
m_sequence = 0;
|
||||
m_sequence = 1;
|
||||
m_paused = 1;
|
||||
|
||||
uv_async_init(uv_default_loop(), &m_async, Workers::onResult);
|
||||
|
@ -121,6 +121,11 @@ void Workers::stop()
|
|||
m_hashrate->stop();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
auto app = new App(argc, argv);
|
||||
App app(argc, argv);
|
||||
|
||||
return app->exec();
|
||||
return app.exec();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue