Added real graceful exit.

This commit is contained in:
XMRig 2019-03-16 00:44:15 +07:00
parent 1e62943010
commit ba68fb6c53
41 changed files with 391 additions and 303 deletions

View file

@ -84,7 +84,7 @@ set(HEADERS
src/Summary.h src/Summary.h
src/version.h src/version.h
src/workers/CpuThread.h src/workers/CpuThread.h
src/workers/Handle.h src/workers/ThreadHandle.h
src/workers/Hashrate.h src/workers/Hashrate.h
src/workers/MultiWorker.h src/workers/MultiWorker.h
src/workers/Worker.h src/workers/Worker.h
@ -131,7 +131,6 @@ set(SOURCES
src/base/net/stratum/strategies/SinglePoolStrategy.cpp src/base/net/stratum/strategies/SinglePoolStrategy.cpp
src/base/tools/Arguments.cpp src/base/tools/Arguments.cpp
src/base/tools/Buffer.cpp src/base/tools/Buffer.cpp
src/base/tools/Handle.cpp
src/base/tools/String.cpp src/base/tools/String.cpp
src/common/config/CommonConfig.cpp src/common/config/CommonConfig.cpp
src/common/config/ConfigLoader.cpp src/common/config/ConfigLoader.cpp
@ -151,7 +150,7 @@ set(SOURCES
src/net/strategies/DonateStrategy.cpp src/net/strategies/DonateStrategy.cpp
src/Summary.cpp src/Summary.cpp
src/workers/CpuThread.cpp src/workers/CpuThread.cpp
src/workers/Handle.cpp src/workers/ThreadHandle.cpp
src/workers/Hashrate.cpp src/workers/Hashrate.cpp
src/workers/MultiWorker.cpp src/workers/MultiWorker.cpp
src/workers/Worker.cpp src/workers/Worker.cpp

View file

@ -187,8 +187,14 @@ void xmrig::App::onSignal(int signum)
void xmrig::App::close() void xmrig::App::close()
{ {
m_controller->network()->stop(); # ifndef XMRIG_NO_HTTPD
Workers::stop(); m_httpd->stop();
# endif
uv_stop(uv_default_loop()); m_signals->stop();
m_console->stop();
m_controller->stop();
Workers::stop();
Log::release();
} }

View file

@ -31,13 +31,13 @@
#include "common/interfaces/IConsoleListener.h" #include "common/interfaces/IConsoleListener.h"
class Console;
class Httpd; class Httpd;
namespace xmrig { namespace xmrig {
class Console;
class Controller; class Controller;
class Network; class Network;
class Process; class Process;

View file

@ -59,11 +59,11 @@ inline static const char *asmName(xmrig::Assembly assembly, bool colors)
static void print_memory(xmrig::Config *config) { static void print_memory(xmrig::Config *config) {
# ifdef _WIN32 # ifdef _WIN32
if (config->isColors()) { if (config->isColors()) {
Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%s", xmrig::Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%s",
"HUGE PAGES", Mem::isHugepagesAvailable() ? "\x1B[1;32mavailable" : "\x1B[01;31munavailable"); "HUGE PAGES", Mem::isHugepagesAvailable() ? "\x1B[1;32mavailable" : "\x1B[01;31munavailable");
} }
else { else {
Log::i()->text(" * %-13s%s", "HUGE PAGES", Mem::isHugepagesAvailable() ? "available" : "unavailable"); xmrig::Log::i()->text(" * %-13s%s", "HUGE PAGES", Mem::isHugepagesAvailable() ? "available" : "unavailable");
} }
# endif # endif
} }
@ -108,7 +108,7 @@ static void print_threads(xmrig::Config *config)
snprintf(buf, sizeof buf, ", affinity=0x%" PRIX64, config->affinity()); snprintf(buf, sizeof buf, ", affinity=0x%" PRIX64, config->affinity());
} }
Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%d") WHITE_BOLD(", %s, av=%d, %sdonate=%d%%") WHITE_BOLD("%s") xmrig::Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%d") WHITE_BOLD(", %s, av=%d, %sdonate=%d%%") WHITE_BOLD("%s")
: " * %-13s%d, %s, av=%d, %sdonate=%d%%%s", : " * %-13s%d, %s, av=%d, %sdonate=%d%%%s",
"THREADS", "THREADS",
config->threadsCount(), config->threadsCount(),
@ -119,7 +119,7 @@ static void print_threads(xmrig::Config *config)
buf); buf);
} }
else { else {
Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%d") WHITE_BOLD(", %s, %sdonate=%d%%") xmrig::Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%d") WHITE_BOLD(", %s, %sdonate=%d%%")
: " * %-13s%d, %s, %sdonate=%d%%", : " * %-13s%d, %s, %sdonate=%d%%",
"THREADS", "THREADS",
config->threadsCount(), config->threadsCount(),
@ -132,11 +132,11 @@ static void print_threads(xmrig::Config *config)
if (config->assembly() == xmrig::ASM_AUTO) { if (config->assembly() == xmrig::ASM_AUTO) {
const xmrig::Assembly assembly = xmrig::Cpu::info()->assembly(); const xmrig::Assembly assembly = xmrig::Cpu::info()->assembly();
Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13sauto:%s") xmrig::Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13sauto:%s")
: " * %-13sauto:%s", "ASSEMBLY", asmName(assembly, config->isColors())); : " * %-13sauto:%s", "ASSEMBLY", asmName(assembly, config->isColors()));
} }
else { else {
Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s%s") : " * %-13s%s", "ASSEMBLY", asmName(config->assembly(), config->isColors())); xmrig::Log::i()->text(config->isColors() ? GREEN_BOLD(" * ") WHITE_BOLD("%-13s%s") : " * %-13s%s", "ASSEMBLY", asmName(config->assembly(), config->isColors()));
} }
# endif # endif
} }
@ -145,12 +145,12 @@ static void print_threads(xmrig::Config *config)
static void print_commands(xmrig::Config *config) static void print_commands(xmrig::Config *config)
{ {
if (config->isColors()) { if (config->isColors()) {
Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("COMMANDS ") MAGENTA_BOLD("h") WHITE_BOLD("ashrate, ") xmrig::Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("COMMANDS ") MAGENTA_BOLD("h") WHITE_BOLD("ashrate, ")
MAGENTA_BOLD("p") WHITE_BOLD("ause, ") MAGENTA_BOLD("p") WHITE_BOLD("ause, ")
MAGENTA_BOLD("r") WHITE_BOLD("esume")); MAGENTA_BOLD("r") WHITE_BOLD("esume"));
} }
else { else {
Log::i()->text(" * COMMANDS 'h' hashrate, 'p' pause, 'r' resume"); xmrig::Log::i()->text(" * COMMANDS 'h' hashrate, 'p' pause, 'r' resume");
} }
} }

View file

@ -5,8 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 SChernykh <https://github.com/SChernykh> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -44,20 +44,31 @@ xmrig::Signals::Signals(ISignalListener *listener)
m_signals[i] = signal; m_signals[i] = signal;
uv_signal_init(uv_default_loop(), signal); uv_signal_init(uv_default_loop(), signal);
uv_signal_start(signal, xmrig::Signals::onSignal, signums[i]); uv_signal_start(signal, Signals::onSignal, signums[i]);
} }
} }
xmrig::Signals::~Signals() xmrig::Signals::~Signals()
{ {
stop();
}
void xmrig::Signals::stop()
{
if (!m_signals[0]) {
return;
}
for (size_t i = 0; i < kSignalsCount; ++i) { for (size_t i = 0; i < kSignalsCount; ++i) {
Handle::close(m_signals[i]); Handle::close(m_signals[i]);
m_signals[i] = nullptr;
} }
} }
void xmrig::Signals::onSignal(uv_signal_t *handle, int signum) void xmrig::Signals::onSignal(uv_signal_t *handle, int signum)
{ {
static_cast<xmrig::Signals *>(handle->data)->m_listener->onSignal(signum); static_cast<Signals *>(handle->data)->m_listener->onSignal(signum);
} }

View file

@ -46,6 +46,8 @@ public:
Signals(ISignalListener *listener); Signals(ISignalListener *listener);
~Signals(); ~Signals();
void stop();
private: private:
void close(int signum); void close(int signum);

View file

@ -52,9 +52,9 @@ xmrig::Dns::Dns(IDnsListener *listener) :
xmrig::Dns::~Dns() xmrig::Dns::~Dns()
{ {
Handle::close(m_resolver);
m_storage.release(m_key); m_storage.release(m_key);
Handle::close(m_resolver);
} }

View file

@ -1,79 +0,0 @@
/* 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 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/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/>.
*/
#include <uv.h>
#include "base/tools/Handle.h"
void xmrig::Handle::close(uv_fs_event_t *handle)
{
if (handle) {
uv_fs_event_stop(handle);
close(reinterpret_cast<uv_handle_t *>(handle));
}
}
void xmrig::Handle::close(uv_getaddrinfo_t *handle)
{
if (handle) {
uv_cancel(reinterpret_cast<uv_req_t *>(handle));
close(reinterpret_cast<uv_handle_t *>(handle));
}
}
void xmrig::Handle::close(uv_handle_t *handle)
{
uv_close(handle, [](uv_handle_t *handle) { delete handle; });
}
void xmrig::Handle::close(uv_signal_t *handle)
{
if (handle) {
uv_signal_stop(handle);
close(reinterpret_cast<uv_handle_t *>(handle));
}
}
void xmrig::Handle::close(uv_tcp_t *handle)
{
if (handle) {
close(reinterpret_cast<uv_handle_t *>(handle));
}
}
void xmrig::Handle::close(uv_timer_s *handle)
{
if (handle) {
uv_timer_stop(handle);
close(reinterpret_cast<uv_handle_t *>(handle));
}
}

View file

@ -26,12 +26,7 @@
#define XMRIG_HANDLE_H #define XMRIG_HANDLE_H
typedef struct uv_fs_event_s uv_fs_event_t; #include <uv.h>
typedef struct uv_getaddrinfo_s uv_getaddrinfo_t;
typedef struct uv_handle_s uv_handle_t;
typedef struct uv_signal_s uv_signal_t;
typedef struct uv_tcp_s uv_tcp_t;
typedef struct uv_timer_s uv_timer_t;
namespace xmrig { namespace xmrig {
@ -40,15 +35,64 @@ namespace xmrig {
class Handle class Handle
{ {
public: public:
static void close(uv_fs_event_t *handle); template<typename T>
static void close(uv_getaddrinfo_t *handle); static inline void close(T handle)
static void close(uv_handle_t *handle); {
static void close(uv_signal_t *handle); if (handle) {
static void close(uv_tcp_t *handle); deleteLater(handle);
static void close(uv_timer_t *handle); }
}
template<typename T>
static inline void deleteLater(T handle)
{
uv_close(reinterpret_cast<uv_handle_t *>(handle), [](uv_handle_t *handle) { delete handle; });
}
}; };
template<>
inline void Handle::close(uv_timer_t *handle)
{
if (handle) {
uv_timer_stop(handle);
deleteLater(handle);
}
}
template<>
inline void Handle::close(uv_signal_t *handle)
{
if (handle) {
uv_signal_stop(handle);
deleteLater(handle);
}
}
template<>
inline void Handle::close(uv_getaddrinfo_t *handle)
{
if (handle) {
uv_cancel(reinterpret_cast<uv_req_t *>(handle));
delete handle;
}
}
template<>
inline void Handle::close(uv_fs_event_t *handle)
{
if (handle) {
uv_fs_event_stop(handle);
deleteLater(handle);
}
}
} /* namespace xmrig */ } /* namespace xmrig */

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -22,26 +23,42 @@
*/ */
#include "base/tools/Handle.h"
#include "common/Console.h" #include "common/Console.h"
#include "interfaces/IConsoleListener.h" #include "interfaces/IConsoleListener.h"
Console::Console(IConsoleListener *listener) xmrig::Console::Console(IConsoleListener *listener)
: m_listener(listener) : m_listener(listener)
{ {
m_tty.data = this; m_tty = new uv_tty_t;
uv_tty_init(uv_default_loop(), &m_tty, 0, 1);
if (!uv_is_readable(reinterpret_cast<uv_stream_t*>(&m_tty))) { m_tty->data = this;
uv_tty_init(uv_default_loop(), m_tty, 0, 1);
if (!uv_is_readable(reinterpret_cast<uv_stream_t*>(m_tty))) {
return; return;
} }
uv_tty_set_mode(&m_tty, UV_TTY_MODE_RAW); uv_tty_set_mode(m_tty, UV_TTY_MODE_RAW);
uv_read_start(reinterpret_cast<uv_stream_t*>(&m_tty), Console::onAllocBuffer, Console::onRead); uv_read_start(reinterpret_cast<uv_stream_t*>(m_tty), Console::onAllocBuffer, Console::onRead);
} }
void Console::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf) xmrig::Console::~Console()
{
stop();
}
void xmrig::Console::stop()
{
Handle::close(m_tty);
m_tty = nullptr;
}
void xmrig::Console::onAllocBuffer(uv_handle_t *handle, size_t, uv_buf_t *buf)
{ {
auto console = static_cast<Console*>(handle->data); auto console = static_cast<Console*>(handle->data);
buf->len = 1; buf->len = 1;
@ -49,7 +66,7 @@ void Console::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t
} }
void Console::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) void xmrig::Console::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
{ {
if (nread < 0) { if (nread < 0) {
return uv_close(reinterpret_cast<uv_handle_t*>(stream), nullptr); return uv_close(reinterpret_cast<uv_handle_t*>(stream), nullptr);

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -21,13 +22,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __CONSOLE_H__ #ifndef XMRIG_CONSOLE_H
#define __CONSOLE_H__ #define XMRIG_CONSOLE_H
#include <uv.h> #include <uv.h>
namespace xmrig {
class IConsoleListener; class IConsoleListener;
@ -35,6 +40,9 @@ class Console
{ {
public: public:
Console(IConsoleListener *listener); Console(IConsoleListener *listener);
~Console();
void stop();
private: private:
static void onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf); static void onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf);
@ -42,8 +50,11 @@ private:
char m_buf[1]; char m_buf[1];
IConsoleListener *m_listener; IConsoleListener *m_listener;
uv_tty_t m_tty; uv_tty_t *m_tty;
}; };
#endif /* __CONSOLE_H__ */ } /* namespace xmrig */
#endif /* XMRIG_CONSOLE_H */

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -27,6 +28,7 @@
#include "api/Api.h" #include "api/Api.h"
#include "base/tools/Handle.h"
#include "common/api/Httpd.h" #include "common/api/Httpd.h"
#include "common/api/HttpReply.h" #include "common/api/HttpReply.h"
#include "common/api/HttpRequest.h" #include "common/api/HttpRequest.h"
@ -41,14 +43,15 @@ Httpd::Httpd(int port, const char *accessToken, bool IPv6, bool restricted) :
m_port(port), m_port(port),
m_daemon(nullptr) m_daemon(nullptr)
{ {
uv_timer_init(uv_default_loop(), &m_timer); m_timer = new uv_timer_t;
m_timer.data = this; uv_timer_init(uv_default_loop(), m_timer);
m_timer->data = this;
} }
Httpd::~Httpd() Httpd::~Httpd()
{ {
uv_timer_stop(&m_timer); stop();
if (m_daemon) { if (m_daemon) {
MHD_stop_daemon(m_daemon); MHD_stop_daemon(m_daemon);
@ -82,15 +85,22 @@ bool Httpd::start()
} }
# if MHD_VERSION >= 0x00093900 # if MHD_VERSION >= 0x00093900
uv_timer_start(&m_timer, Httpd::onTimer, kIdleInterval, kIdleInterval); uv_timer_start(m_timer, Httpd::onTimer, kIdleInterval, kIdleInterval);
# else # else
uv_timer_start(&m_timer, Httpd::onTimer, kActiveInterval, kActiveInterval); uv_timer_start(m_timer, Httpd::onTimer, kActiveInterval, kActiveInterval);
# endif # endif
return true; return true;
} }
void Httpd::stop()
{
xmrig::Handle::close(m_timer);
m_timer = nullptr;
}
int Httpd::process(xmrig::HttpRequest &req) int Httpd::process(xmrig::HttpRequest &req)
{ {
xmrig::HttpReply reply; xmrig::HttpReply reply;
@ -115,11 +125,11 @@ void Httpd::run()
# if MHD_VERSION >= 0x00093900 # if MHD_VERSION >= 0x00093900
const MHD_DaemonInfo *info = MHD_get_daemon_info(m_daemon, MHD_DAEMON_INFO_CURRENT_CONNECTIONS); const MHD_DaemonInfo *info = MHD_get_daemon_info(m_daemon, MHD_DAEMON_INFO_CURRENT_CONNECTIONS);
if (m_idle && info->num_connections) { if (m_idle && info->num_connections) {
uv_timer_set_repeat(&m_timer, kActiveInterval); uv_timer_set_repeat(m_timer, kActiveInterval);
m_idle = false; m_idle = false;
} }
else if (!m_idle && !info->num_connections) { else if (!m_idle && !info->num_connections) {
uv_timer_set_repeat(&m_timer, kIdleInterval); uv_timer_set_repeat(m_timer, kIdleInterval);
m_idle = true; m_idle = true;
} }
# endif # endif

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -21,8 +22,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __HTTPD_H__ #ifndef XMRIG_HTTPD_H
#define __HTTPD_H__ #define XMRIG_HTTPD_H
#include <uv.h> #include <uv.h>
@ -47,6 +48,7 @@ public:
Httpd(int port, const char *accessToken, bool IPv6, bool restricted); Httpd(int port, const char *accessToken, bool IPv6, bool restricted);
~Httpd(); ~Httpd();
bool start(); bool start();
void stop();
private: private:
constexpr static const int kIdleInterval = 200; constexpr static const int kIdleInterval = 200;
@ -64,7 +66,7 @@ private:
const char *m_accessToken; const char *m_accessToken;
const int m_port; const int m_port;
MHD_Daemon *m_daemon; MHD_Daemon *m_daemon;
uv_timer_t m_timer; uv_timer_t *m_timer;
}; };
#endif /* __HTTPD_H__ */ #endif /* XMRIG_HTTPD_H */

View file

@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -21,17 +22,23 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __ICONSOLELISTENER_H__ #ifndef XMRIG_ICONSOLELISTENER_H
#define __ICONSOLELISTENER_H__ #define XMRIG_ICONSOLELISTENER_H
namespace xmrig {
class IConsoleListener class IConsoleListener
{ {
public: public:
virtual ~IConsoleListener() {} virtual ~IConsoleListener() = default;
virtual void onConsoleCommand(char command) = 0; virtual void onConsoleCommand(char command) = 0;
}; };
#endif // __ICONSOLELISTENER_H__ } /* namespace xmrig */
#endif // XMRIG_ICONSOLELISTENER_H

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -21,14 +22,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __ILOGBACKEND_H__ #ifndef XMRIG_ILOGBACKEND_H
#define __ILOGBACKEND_H__ #define XMRIG_ILOGBACKEND_H
#include <stdarg.h> #include <stdarg.h>
#include <stddef.h> #include <stddef.h>
namespace xmrig {
class ILogBackend class ILogBackend
{ {
public: public:
@ -46,11 +50,14 @@ public:
constexpr static const size_t kBufferSize = 512; constexpr static const size_t kBufferSize = 512;
# endif # endif
virtual ~ILogBackend() {} virtual ~ILogBackend() = default;
virtual void message(Level level, const char* fmt, va_list args) = 0; virtual void message(Level level, const char* fmt, va_list args) = 0;
virtual void text(const char* fmt, va_list args) = 0; virtual void text(const char* fmt, va_list args) = 0;
}; };
#endif // __ILOGBACKEND_H__ } /* namespace xmrig */
#endif // XMRIG_ILOGBACKEND_H

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -38,12 +39,12 @@
#include "common/log/Log.h" #include "common/log/Log.h"
BasicLog::BasicLog() xmrig::BasicLog::BasicLog()
{ {
} }
void BasicLog::message(Level level, const char* fmt, va_list args) void xmrig::BasicLog::message(Level level, const char* fmt, va_list args)
{ {
time_t now = time(nullptr); time_t now = time(nullptr);
tm stime; tm stime;
@ -70,7 +71,7 @@ void BasicLog::message(Level level, const char* fmt, va_list args)
} }
void BasicLog::text(const char* fmt, va_list args) void xmrig::BasicLog::text(const char* fmt, va_list args)
{ {
snprintf(m_fmt, sizeof(m_fmt) - 1, "%s%s", fmt, Log::endl(false)); snprintf(m_fmt, sizeof(m_fmt) - 1, "%s%s", fmt, Log::endl(false));
@ -78,7 +79,7 @@ void BasicLog::text(const char* fmt, va_list args)
} }
void BasicLog::print(va_list args) void xmrig::BasicLog::print(va_list args)
{ {
if (vsnprintf(m_buf, sizeof(m_buf) - 1, m_fmt, args) <= 0) { if (vsnprintf(m_buf, sizeof(m_buf) - 1, m_fmt, args) <= 0) {
return; return;

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -21,8 +22,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __BASICLOG_H__ #ifndef XMRIG_BASICLOG_H
#define __BASICLOG_H__ #define XMRIG_BASICLOG_H
#include <uv.h> #include <uv.h>
@ -32,8 +33,6 @@
namespace xmrig { namespace xmrig {
class Controller;
}
class BasicLog : public ILogBackend class BasicLog : public ILogBackend
@ -52,4 +51,7 @@ private:
char m_fmt[256]; char m_fmt[256];
}; };
#endif /* __BASICLOG_H__ */
} /* namespace xmrig */
#endif /* XMRIG_BASICLOG_H */

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -34,24 +35,24 @@
#endif #endif
#include "base/tools/Handle.h"
#include "common/log/ConsoleLog.h" #include "common/log/ConsoleLog.h"
#include "common/log/Log.h" #include "common/log/Log.h"
#include "core/Config.h"
#include "core/Controller.h"
ConsoleLog::ConsoleLog(xmrig::Controller *controller) : xmrig::ConsoleLog::ConsoleLog() :
m_stream(nullptr), m_stream(nullptr)
m_controller(controller)
{ {
if (uv_tty_init(uv_default_loop(), &m_tty, 1, 0) < 0) { m_tty = new uv_tty_t;
if (uv_tty_init(uv_default_loop(), m_tty, 1, 0) < 0) {
Log::colors = false; Log::colors = false;
return; return;
} }
uv_tty_set_mode(&m_tty, UV_TTY_MODE_NORMAL); uv_tty_set_mode(m_tty, UV_TTY_MODE_NORMAL);
m_uvBuf.base = m_buf; m_uvBuf.base = m_buf;
m_stream = reinterpret_cast<uv_stream_t*>(&m_tty); m_stream = reinterpret_cast<uv_stream_t*>(m_tty);
# ifdef WIN32 # ifdef WIN32
HANDLE handle = GetStdHandle(STD_INPUT_HANDLE); HANDLE handle = GetStdHandle(STD_INPUT_HANDLE);
@ -66,7 +67,13 @@ ConsoleLog::ConsoleLog(xmrig::Controller *controller) :
} }
void ConsoleLog::message(Level level, const char* fmt, va_list args) xmrig::ConsoleLog::~ConsoleLog()
{
Handle::close(m_tty);
}
void xmrig::ConsoleLog::message(Level level, const char* fmt, va_list args)
{ {
time_t now = time(nullptr); time_t now = time(nullptr);
tm stime; tm stime;
@ -77,8 +84,6 @@ void ConsoleLog::message(Level level, const char* fmt, va_list args)
localtime_r(&now, &stime); localtime_r(&now, &stime);
# endif # endif
const bool isColors = m_controller->config()->isColors();
snprintf(m_fmt, sizeof(m_fmt) - 1, "[%d-%02d-%02d %02d:%02d:%02d]%s %s%s", snprintf(m_fmt, sizeof(m_fmt) - 1, "[%d-%02d-%02d %02d:%02d:%02d]%s %s%s",
stime.tm_year + 1900, stime.tm_year + 1900,
stime.tm_mon + 1, stime.tm_mon + 1,
@ -86,24 +91,24 @@ void ConsoleLog::message(Level level, const char* fmt, va_list args)
stime.tm_hour, stime.tm_hour,
stime.tm_min, stime.tm_min,
stime.tm_sec, stime.tm_sec,
Log::colorByLevel(level, isColors), Log::colorByLevel(level, Log::colors),
fmt, fmt,
Log::endl(isColors) Log::endl(Log::colors)
); );
print(args); print(args);
} }
void ConsoleLog::text(const char* fmt, va_list args) void xmrig::ConsoleLog::text(const char* fmt, va_list args)
{ {
snprintf(m_fmt, sizeof(m_fmt) - 1, "%s%s", fmt, Log::endl(m_controller->config()->isColors())); snprintf(m_fmt, sizeof(m_fmt) - 1, "%s%s", fmt, Log::endl(Log::colors));
print(args); print(args);
} }
bool ConsoleLog::isWritable() const bool xmrig::ConsoleLog::isWritable() const
{ {
if (!m_stream || uv_is_writable(m_stream) != 1) { if (!m_stream || uv_is_writable(m_stream) != 1) {
return false; return false;
@ -114,7 +119,7 @@ bool ConsoleLog::isWritable() const
} }
void ConsoleLog::print(va_list args) void xmrig::ConsoleLog::print(va_list args)
{ {
m_uvBuf.len = vsnprintf(m_buf, sizeof(m_buf) - 1, m_fmt, args); m_uvBuf.len = vsnprintf(m_buf, sizeof(m_buf) - 1, m_fmt, args);
if (m_uvBuf.len <= 0) { if (m_uvBuf.len <= 0) {

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -21,8 +22,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __CONSOLELOG_H__ #ifndef XMRIG_CONSOLELOG_H
#define __CONSOLELOG_H__ #define XMRIG_CONSOLELOG_H
#include <uv.h> #include <uv.h>
@ -32,15 +33,15 @@
namespace xmrig { namespace xmrig {
class Controller;
}
class ConsoleLog : public ILogBackend class ConsoleLog : public ILogBackend
{ {
public: public:
ConsoleLog(xmrig::Controller *controller); ConsoleLog();
~ConsoleLog() override;
protected:
void message(Level level, const char *fmt, va_list args) override; void message(Level level, const char *fmt, va_list args) override;
void text(const char *fmt, va_list args) override; void text(const char *fmt, va_list args) override;
@ -52,8 +53,11 @@ private:
char m_fmt[256]; char m_fmt[256];
uv_buf_t m_uvBuf; uv_buf_t m_uvBuf;
uv_stream_t *m_stream; uv_stream_t *m_stream;
uv_tty_t m_tty; uv_tty_t *m_tty;
xmrig::Controller *m_controller;
}; };
#endif /* __CONSOLELOG_H__ */
} /* namespace xmrig */
#endif /* XMRIG_CONSOLELOG_H */

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -31,12 +32,9 @@
#include "common/log/FileLog.h" #include "common/log/FileLog.h"
#include "common/log/Log.h" #include "common/log/Log.h"
#include "core/Config.h"
#include "core/Controller.h"
FileLog::FileLog(xmrig::Controller *controller, const char *fileName) : xmrig::FileLog::FileLog(const char *fileName)
m_controller(controller)
{ {
uv_fs_t req; uv_fs_t req;
m_file = uv_fs_open(uv_default_loop(), &req, fileName, O_CREAT | O_APPEND | O_WRONLY, 0644, nullptr); m_file = uv_fs_open(uv_default_loop(), &req, fileName, O_CREAT | O_APPEND | O_WRONLY, 0644, nullptr);
@ -44,7 +42,7 @@ FileLog::FileLog(xmrig::Controller *controller, const char *fileName) :
} }
void FileLog::message(Level level, const char* fmt, va_list args) void xmrig::FileLog::message(Level level, const char* fmt, va_list args)
{ {
if (m_file < 0) { if (m_file < 0) {
return; return;
@ -59,8 +57,6 @@ void FileLog::message(Level level, const char* fmt, va_list args)
localtime_r(&now, &stime); localtime_r(&now, &stime);
# endif # endif
const bool isColors = m_controller->config()->isColors();
snprintf(m_fmt, sizeof(m_fmt) - 1, "[%d-%02d-%02d %02d:%02d:%02d]%s %s%s", snprintf(m_fmt, sizeof(m_fmt) - 1, "[%d-%02d-%02d %02d:%02d:%02d]%s %s%s",
stime.tm_year + 1900, stime.tm_year + 1900,
stime.tm_mon + 1, stime.tm_mon + 1,
@ -68,9 +64,9 @@ void FileLog::message(Level level, const char* fmt, va_list args)
stime.tm_hour, stime.tm_hour,
stime.tm_min, stime.tm_min,
stime.tm_sec, stime.tm_sec,
Log::colorByLevel(level, isColors), Log::colorByLevel(level, Log::colors),
fmt, fmt,
Log::endl(isColors) Log::endl(Log::colors)
); );
char *buf = new char[kBufferSize]; char *buf = new char[kBufferSize];
@ -80,13 +76,13 @@ void FileLog::message(Level level, const char* fmt, va_list args)
} }
void FileLog::text(const char* fmt, va_list args) void xmrig::FileLog::text(const char* fmt, va_list args)
{ {
message(INFO, fmt, args); message(INFO, fmt, args);
} }
void FileLog::onWrite(uv_fs_t *req) void xmrig::FileLog::onWrite(uv_fs_t *req)
{ {
delete [] static_cast<char *>(req->data); delete [] static_cast<char *>(req->data);
@ -95,7 +91,7 @@ void FileLog::onWrite(uv_fs_t *req)
} }
void FileLog::write(char *data, size_t size) void xmrig::FileLog::write(char *data, size_t size)
{ {
uv_buf_t buf = uv_buf_init(data, (unsigned int) size); uv_buf_t buf = uv_buf_init(data, (unsigned int) size);
uv_fs_t *req = new uv_fs_t; uv_fs_t *req = new uv_fs_t;

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -21,8 +22,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __FILELOG_H__ #ifndef XMRIG_FILELOG_H
#define __FILELOG_H__ #define XMRIG_FILELOG_H
#include <uv.h> #include <uv.h>
@ -32,14 +33,12 @@
namespace xmrig { namespace xmrig {
class Controller;
}
class FileLog : public ILogBackend class FileLog : public ILogBackend
{ {
public: public:
FileLog(xmrig::Controller *controller, const char *fileName); FileLog(const char *fileName);
void message(Level level, const char* fmt, va_list args) override; void message(Level level, const char* fmt, va_list args) override;
void text(const char* fmt, va_list args) override; void text(const char* fmt, va_list args) override;
@ -51,7 +50,10 @@ private:
char m_fmt[256]; char m_fmt[256];
int m_file; int m_file;
xmrig::Controller *m_controller;
}; };
#endif /* __FILELOG_H__ */
} /* namespace xmrig */
#endif /* XMRIG_FILELOG_H */

View file

@ -35,6 +35,8 @@
#include "common/log/Log.h" #include "common/log/Log.h"
namespace xmrig {
Log *Log::m_self = nullptr; Log *Log::m_self = nullptr;
bool Log::colors = true; bool Log::colors = true;
@ -51,8 +53,10 @@ static const char *color[5] = {
# endif # endif
}; };
} /* namespace xmrig */
void Log::message(ILogBackend::Level level, const char* fmt, ...)
void xmrig::Log::message(ILogBackend::Level level, const char* fmt, ...)
{ {
uv_mutex_lock(&m_mutex); uv_mutex_lock(&m_mutex);
@ -72,7 +76,7 @@ void Log::message(ILogBackend::Level level, const char* fmt, ...)
} }
void Log::text(const char* fmt, ...) void xmrig::Log::text(const char* fmt, ...)
{ {
uv_mutex_lock(&m_mutex); uv_mutex_lock(&m_mutex);
@ -92,7 +96,7 @@ void Log::text(const char* fmt, ...)
} }
const char *Log::colorByLevel(ILogBackend::Level level, bool isColors) const char *xmrig::Log::colorByLevel(ILogBackend::Level level, bool isColors)
{ {
if (!isColors) { if (!isColors) {
return ""; return "";
@ -102,7 +106,7 @@ const char *Log::colorByLevel(ILogBackend::Level level, bool isColors)
} }
const char *Log::endl(bool isColors) const char *xmrig::Log::endl(bool isColors)
{ {
# ifdef _WIN32 # ifdef _WIN32
return isColors ? "\x1B[0m\r\n" : "\r\n"; return isColors ? "\x1B[0m\r\n" : "\r\n";
@ -112,7 +116,7 @@ const char *Log::endl(bool isColors)
} }
void Log::defaultInit() void xmrig::Log::defaultInit()
{ {
m_self = new Log(); m_self = new Log();
@ -120,8 +124,10 @@ void Log::defaultInit()
} }
Log::~Log() xmrig::Log::~Log()
{ {
m_self = nullptr;
for (auto backend : m_backends) { for (auto backend : m_backends) {
delete backend; delete backend;
} }

View file

@ -34,6 +34,9 @@
#include "common/interfaces/ILogBackend.h" #include "common/interfaces/ILogBackend.h"
namespace xmrig {
class Log class Log
{ {
public: public:
@ -68,6 +71,9 @@ private:
}; };
} /* namespace xmrig */
#define RED_BOLD(x) "\x1B[1;31m" x "\x1B[0m" #define RED_BOLD(x) "\x1B[1;31m" x "\x1B[0m"
#define RED(x) "\x1B[0;31m" x "\x1B[0m" #define RED(x) "\x1B[0;31m" x "\x1B[0m"
#define GREEN_BOLD(x) "\x1B[1;32m" x "\x1B[0m" #define GREEN_BOLD(x) "\x1B[1;32m" x "\x1B[0m"
@ -83,20 +89,20 @@ private:
#define GRAY(x) "\x1B[1;30m" x "\x1B[0m" #define GRAY(x) "\x1B[1;30m" x "\x1B[0m"
#define LOG_ERR(x, ...) Log::i()->message(ILogBackend::ERR, x, ##__VA_ARGS__) #define LOG_ERR(x, ...) xmrig::Log::i()->message(xmrig::ILogBackend::ERR, x, ##__VA_ARGS__)
#define LOG_WARN(x, ...) Log::i()->message(ILogBackend::WARNING, x, ##__VA_ARGS__) #define LOG_WARN(x, ...) xmrig::Log::i()->message(xmrig::ILogBackend::WARNING, x, ##__VA_ARGS__)
#define LOG_NOTICE(x, ...) Log::i()->message(ILogBackend::NOTICE, x, ##__VA_ARGS__) #define LOG_NOTICE(x, ...) xmrig::Log::i()->message(xmrig::ILogBackend::NOTICE, x, ##__VA_ARGS__)
#define LOG_INFO(x, ...) Log::i()->message(ILogBackend::INFO, x, ##__VA_ARGS__) #define LOG_INFO(x, ...) xmrig::Log::i()->message(xmrig::ILogBackend::INFO, x, ##__VA_ARGS__)
#ifdef APP_DEBUG #ifdef APP_DEBUG
# define LOG_DEBUG(x, ...) Log::i()->message(ILogBackend::DEBUG, x, ##__VA_ARGS__) # define LOG_DEBUG(x, ...) xmrig::Log::i()->message(xmrig::ILogBackend::DEBUG, x, ##__VA_ARGS__)
#else #else
# define LOG_DEBUG(x, ...) # define LOG_DEBUG(x, ...)
#endif #endif
#if defined(APP_DEBUG) || defined(APP_DEVEL) #if defined(APP_DEBUG) || defined(APP_DEVEL)
# define LOG_DEBUG_ERR(x, ...) Log::i()->message(ILogBackend::ERR, x, ##__VA_ARGS__) # define LOG_DEBUG_ERR(x, ...) xmrig::Log::i()->message(xmrig::ILogBackend::ERR, x, ##__VA_ARGS__)
# define LOG_DEBUG_WARN(x, ...) Log::i()->message(ILogBackend::WARNING, x, ##__VA_ARGS__) # define LOG_DEBUG_WARN(x, ...) xmrig::Log::i()->message(xmrig::ILogBackend::WARNING, x, ##__VA_ARGS__)
#else #else
# define LOG_DEBUG_ERR(x, ...) # define LOG_DEBUG_ERR(x, ...)
# define LOG_DEBUG_WARN(x, ...) # define LOG_DEBUG_WARN(x, ...)

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -29,19 +30,19 @@
#include "version.h" #include "version.h"
SysLog::SysLog() xmrig::SysLog::SysLog()
{ {
openlog(APP_ID, LOG_PID, LOG_USER); openlog(APP_ID, LOG_PID, LOG_USER);
} }
void SysLog::message(Level level, const char *fmt, va_list args) void xmrig::SysLog::message(Level level, const char *fmt, va_list args)
{ {
vsyslog(static_cast<int>(level), fmt, args); vsyslog(static_cast<int>(level), fmt, args);
} }
void SysLog::text(const char *fmt, va_list args) void xmrig::SysLog::text(const char *fmt, va_list args)
{ {
vsyslog(LOG_INFO, fmt, args); vsyslog(LOG_INFO, fmt, args);
} }

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -21,13 +22,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __SYSLOG_H__ #ifndef XMRIG_SYSLOG_H
#define __SYSLOG_H__ #define XMRIG_SYSLOG_H
#include "common/interfaces/ILogBackend.h" #include "common/interfaces/ILogBackend.h"
namespace xmrig {
class SysLog : public ILogBackend class SysLog : public ILogBackend
{ {
public: public:
@ -37,4 +41,8 @@ public:
void text(const char *fmt, va_list args) override; void text(const char *fmt, va_list args) override;
}; };
#endif /* __SYSLOG_BACKEND_H__ */
} /* namespace xmrig */
#endif /* XMRIG_SYSLOG_H */

View file

@ -75,8 +75,6 @@ xmrig::Controller::Controller(Process *process)
xmrig::Controller::~Controller() xmrig::Controller::~Controller()
{ {
ConfigLoader::release();
delete d_ptr; delete d_ptr;
} }
@ -109,11 +107,11 @@ int xmrig::Controller::init()
Platform::setProcessPriority(d_ptr->config->priority()); Platform::setProcessPriority(d_ptr->config->priority());
if (!config()->isBackground()) { if (!config()->isBackground()) {
Log::add(new ConsoleLog(this)); Log::add(new ConsoleLog());
} }
if (config()->logFile()) { if (config()->logFile()) {
Log::add(new FileLog(this, config()->logFile())); Log::add(new FileLog(config()->logFile()));
} }
# ifdef HAVE_SYSLOG_H # ifdef HAVE_SYSLOG_H
@ -166,3 +164,12 @@ void xmrig::Controller::onNewConfig(IConfig *config)
delete previousConfig; delete previousConfig;
} }
void xmrig::Controller::stop()
{
ConfigLoader::release();
delete d_ptr->network;
d_ptr->network = nullptr;
}

View file

@ -54,6 +54,7 @@ public:
Network *network() const; Network *network() const;
void addListener(IControllerListener *listener); void addListener(IControllerListener *listener);
void save(); void save();
void stop();
protected: protected:
void onNewConfig(IConfig *config) override; void onNewConfig(IConfig *config) override;

View file

@ -35,6 +35,7 @@
#include "base/net/stratum/Client.h" #include "base/net/stratum/Client.h"
#include "base/net/stratum/SubmitResult.h" #include "base/net/stratum/SubmitResult.h"
#include "base/tools/Chrono.h" #include "base/tools/Chrono.h"
#include "base/tools/Handle.h"
#include "common/log/Log.h" #include "common/log/Log.h"
#include "core/Config.h" #include "core/Config.h"
#include "core/Controller.h" #include "core/Controller.h"
@ -44,7 +45,8 @@
xmrig::Network::Network(Controller *controller) : xmrig::Network::Network(Controller *controller) :
m_donate(nullptr) m_donate(nullptr),
m_timer(nullptr)
{ {
Workers::setListener(this); Workers::setListener(this);
controller->addListener(this); controller->addListener(this);
@ -56,15 +58,21 @@ xmrig::Network::Network(Controller *controller) :
m_donate = new DonateStrategy(controller->config()->donateLevel(), pools.data().front().user(), controller->config()->algorithm().algo(), this); m_donate = new DonateStrategy(controller->config()->donateLevel(), pools.data().front().user(), controller->config()->algorithm().algo(), this);
} }
m_timer.data = this; m_timer = new uv_timer_t;
uv_timer_init(uv_default_loop(), &m_timer); m_timer->data = this;
uv_timer_init(uv_default_loop(), m_timer);
uv_timer_start(&m_timer, Network::onTick, kTickInterval, kTickInterval); uv_timer_start(m_timer, Network::onTick, kTickInterval, kTickInterval);
} }
xmrig::Network::~Network() xmrig::Network::~Network()
{ {
Handle::close(m_timer);
if (m_donate) {
delete m_donate;
}
delete m_strategy; delete m_strategy;
} }
@ -75,16 +83,6 @@ void xmrig::Network::connect()
} }
void xmrig::Network::stop()
{
if (m_donate) {
m_donate->stop();
}
m_strategy->stop();
}
void xmrig::Network::onActive(IStrategy *strategy, Client *client) void xmrig::Network::onActive(IStrategy *strategy, Client *client)
{ {
if (m_donate && m_donate == strategy) { if (m_donate && m_donate == strategy) {

View file

@ -50,7 +50,6 @@ public:
~Network() override; ~Network() override;
void connect(); void connect();
void stop();
protected: protected:
void onActive(IStrategy *strategy, Client *client) override; void onActive(IStrategy *strategy, Client *client) override;
@ -72,7 +71,7 @@ private:
IStrategy *m_donate; IStrategy *m_donate;
IStrategy *m_strategy; IStrategy *m_strategy;
NetworkState m_state; NetworkState m_state;
uv_timer_t m_timer; uv_timer_t *m_timer;
}; };

View file

@ -28,6 +28,7 @@
#include "base/net/stratum/strategies/FailoverStrategy.h" #include "base/net/stratum/strategies/FailoverStrategy.h"
#include "base/net/stratum/strategies/SinglePoolStrategy.h" #include "base/net/stratum/strategies/SinglePoolStrategy.h"
#include "base/tools/Buffer.h" #include "base/tools/Buffer.h"
#include "base/tools/Handle.h"
#include "common/crypto/keccak.h" #include "common/crypto/keccak.h"
#include "common/Platform.h" #include "common/Platform.h"
#include "common/xmrig.h" #include "common/xmrig.h"
@ -71,8 +72,9 @@ xmrig::DonateStrategy::DonateStrategy(int level, const char *user, Algo algo, IS
m_strategy = new SinglePoolStrategy(m_pools.front(), 1, 2, this, true); m_strategy = new SinglePoolStrategy(m_pools.front(), 1, 2, this, true);
} }
m_timer.data = this; m_timer = new uv_timer_t;
uv_timer_init(uv_default_loop(), &m_timer); m_timer->data = this;
uv_timer_init(uv_default_loop(), m_timer);
idle(m_idleTime * randomf(0.5, 1.5)); idle(m_idleTime * randomf(0.5, 1.5));
} }
@ -80,6 +82,7 @@ xmrig::DonateStrategy::DonateStrategy(int level, const char *user, Algo algo, IS
xmrig::DonateStrategy::~DonateStrategy() xmrig::DonateStrategy::~DonateStrategy()
{ {
Handle::close(m_timer);
delete m_strategy; delete m_strategy;
} }
@ -104,7 +107,7 @@ void xmrig::DonateStrategy::setAlgo(const xmrig::Algorithm &algo)
void xmrig::DonateStrategy::stop() void xmrig::DonateStrategy::stop()
{ {
uv_timer_stop(&m_timer); uv_timer_stop(m_timer);
m_strategy->stop(); m_strategy->stop();
} }
@ -125,7 +128,7 @@ void xmrig::DonateStrategy::tick(uint64_t now)
void xmrig::DonateStrategy::onActive(IStrategy *strategy, Client *client) void xmrig::DonateStrategy::onActive(IStrategy *strategy, Client *client)
{ {
if (!isActive()) { if (!isActive()) {
uv_timer_start(&m_timer, DonateStrategy::onTimer, m_donateTime, 0); uv_timer_start(m_timer, DonateStrategy::onTimer, m_donateTime, 0);
} }
m_active = true; m_active = true;
@ -154,7 +157,7 @@ void xmrig::DonateStrategy::onResultAccepted(IStrategy *strategy, Client *client
void xmrig::DonateStrategy::idle(uint64_t timeout) void xmrig::DonateStrategy::idle(uint64_t timeout)
{ {
uv_timer_start(&m_timer, DonateStrategy::onTimer, timeout, 0); uv_timer_start(m_timer, DonateStrategy::onTimer, timeout, 0);
} }

View file

@ -79,7 +79,7 @@ private:
std::vector<Pool> m_pools; std::vector<Pool> m_pools;
uint64_t m_now; uint64_t m_now;
uint64_t m_stop; uint64_t m_stop;
uv_timer_t m_timer; uv_timer_t *m_timer;
}; };

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -29,6 +30,7 @@
#include <stdio.h> #include <stdio.h>
#include "base/tools/Handle.h"
#include "common/log/Log.h" #include "common/log/Log.h"
#include "core/Config.h" #include "core/Config.h"
#include "core/Controller.h" #include "core/Controller.h"
@ -49,6 +51,7 @@ inline static const char *format(double h, char *buf, size_t size)
Hashrate::Hashrate(size_t threads, xmrig::Controller *controller) : Hashrate::Hashrate(size_t threads, xmrig::Controller *controller) :
m_highest(0.0), m_highest(0.0),
m_threads(threads), m_threads(threads),
m_timer(nullptr),
m_controller(controller) m_controller(controller)
{ {
m_counts = new uint64_t*[threads]; m_counts = new uint64_t*[threads];
@ -64,10 +67,11 @@ Hashrate::Hashrate(size_t threads, xmrig::Controller *controller) :
const int printTime = controller->config()->printTime(); const int printTime = controller->config()->printTime();
if (printTime > 0) { if (printTime > 0) {
uv_timer_init(uv_default_loop(), &m_timer); m_timer = new uv_timer_t;
m_timer.data = this; uv_timer_init(uv_default_loop(), m_timer);
m_timer->data = this;
uv_timer_start(&m_timer, Hashrate::onReport, (printTime + 4) * 1000, printTime * 1000); uv_timer_start(m_timer, Hashrate::onReport, (printTime + 4) * 1000, printTime * 1000);
} }
} }
@ -171,7 +175,8 @@ void Hashrate::print() const
void Hashrate::stop() void Hashrate::stop()
{ {
uv_timer_stop(&m_timer); xmrig::Handle::close(m_timer);
m_timer = nullptr;
} }

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -21,8 +22,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __HASHRATE_H__ #ifndef XMRIG_HASHRATE_H
#define __HASHRATE_H__ #define XMRIG_HASHRATE_H
#include <stdint.h> #include <stdint.h>
@ -67,9 +68,9 @@ private:
uint32_t* m_top; uint32_t* m_top;
uint64_t** m_counts; uint64_t** m_counts;
uint64_t** m_timestamps; uint64_t** m_timestamps;
uv_timer_t m_timer; uv_timer_t *m_timer;
xmrig::Controller *m_controller; xmrig::Controller *m_controller;
}; };
#endif /* __HASHRATE_H__ */ #endif /* XMRIG_HASHRATE_H */

View file

@ -35,7 +35,7 @@
template<size_t N> template<size_t N>
MultiWorker<N>::MultiWorker(Handle *handle) MultiWorker<N>::MultiWorker(ThreadHandle *handle)
: Worker(handle) : Worker(handle)
{ {
m_memory = Mem::create(m_ctx, m_thread->algorithm(), N); m_memory = Mem::create(m_ctx, m_thread->algorithm(), N);

View file

@ -40,7 +40,7 @@ template<size_t N>
class MultiWorker : public Worker class MultiWorker : public Worker
{ {
public: public:
MultiWorker(Handle *handle); MultiWorker(ThreadHandle *handle);
~MultiWorker(); ~MultiWorker();
protected: protected:

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -22,10 +23,10 @@
*/ */
#include "workers/Handle.h" #include "workers/ThreadHandle.h"
Handle::Handle(xmrig::IThread *config, uint32_t offset, size_t totalWays) : ThreadHandle::ThreadHandle(xmrig::IThread *config, uint32_t offset, size_t totalWays) :
m_worker(nullptr), m_worker(nullptr),
m_totalWays(totalWays), m_totalWays(totalWays),
m_offset(offset), m_offset(offset),
@ -34,13 +35,13 @@ Handle::Handle(xmrig::IThread *config, uint32_t offset, size_t totalWays) :
} }
void Handle::join() void ThreadHandle::join()
{ {
uv_thread_join(&m_thread); uv_thread_join(&m_thread);
} }
void Handle::start(void (*callback) (void *)) void ThreadHandle::start(void (*callback) (void *))
{ {
uv_thread_create(&m_thread, callback, this); uv_thread_create(&m_thread, callback, this);
} }

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -21,8 +22,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __HANDLE_H__ #ifndef XMRIG_THREADHANDLE_H
#define __HANDLE_H__ #define XMRIG_THREADHANDLE_H
#include <assert.h> #include <assert.h>
@ -36,10 +37,10 @@
class IWorker; class IWorker;
class Handle class ThreadHandle
{ {
public: public:
Handle(xmrig::IThread *config, uint32_t offset, size_t totalWays); ThreadHandle(xmrig::IThread *config, uint32_t offset, size_t totalWays);
void join(); void join();
void start(void (*callback) (void *)); void start(void (*callback) (void *));
@ -59,4 +60,4 @@ private:
}; };
#endif /* __HANDLE_H__ */ #endif /* XMRIG_THREADHANDLE_H */

View file

@ -27,11 +27,11 @@
#include "common/cpu/Cpu.h" #include "common/cpu/Cpu.h"
#include "common/Platform.h" #include "common/Platform.h"
#include "workers/CpuThread.h" #include "workers/CpuThread.h"
#include "workers/Handle.h" #include "workers/ThreadHandle.h"
#include "workers/Worker.h" #include "workers/Worker.h"
Worker::Worker(Handle *handle) : Worker::Worker(ThreadHandle *handle) :
m_id(handle->threadId()), m_id(handle->threadId()),
m_totalWays(handle->totalWays()), m_totalWays(handle->totalWays()),
m_offset(handle->offset()), m_offset(handle->offset()),

View file

@ -33,7 +33,7 @@
#include "Mem.h" #include "Mem.h"
class Handle; class ThreadHandle;
namespace xmrig { namespace xmrig {
@ -44,7 +44,7 @@ namespace xmrig {
class Worker : public IWorker class Worker : public IWorker
{ {
public: public:
Worker(Handle *handle); Worker(ThreadHandle *handle);
inline const MemInfo &memory() const { return m_memory; } inline const MemInfo &memory() const { return m_memory; }
inline size_t id() const override { return m_id; } inline size_t id() const override { return m_id; }

View file

@ -28,6 +28,7 @@
#include "api/Api.h" #include "api/Api.h"
#include "base/tools/Handle.h"
#include "common/log/Log.h" #include "common/log/Log.h"
#include "core/Config.h" #include "core/Config.h"
#include "core/Controller.h" #include "core/Controller.h"
@ -36,9 +37,9 @@
#include "interfaces/IThread.h" #include "interfaces/IThread.h"
#include "Mem.h" #include "Mem.h"
#include "rapidjson/document.h" #include "rapidjson/document.h"
#include "workers/Handle.h"
#include "workers/Hashrate.h" #include "workers/Hashrate.h"
#include "workers/MultiWorker.h" #include "workers/MultiWorker.h"
#include "workers/ThreadHandle.h"
#include "workers/Workers.h" #include "workers/Workers.h"
@ -51,12 +52,12 @@ Workers::LaunchStatus Workers::m_status;
std::atomic<int> Workers::m_paused; std::atomic<int> Workers::m_paused;
std::atomic<uint64_t> Workers::m_sequence; std::atomic<uint64_t> Workers::m_sequence;
std::list<xmrig::JobResult> Workers::m_queue; std::list<xmrig::JobResult> Workers::m_queue;
std::vector<Handle*> Workers::m_workers; std::vector<ThreadHandle*> Workers::m_workers;
uint64_t Workers::m_ticks = 0; uint64_t Workers::m_ticks = 0;
uv_async_t Workers::m_async; uv_async_t *Workers::m_async = nullptr;
uv_mutex_t Workers::m_mutex; uv_mutex_t Workers::m_mutex;
uv_rwlock_t Workers::m_rwlock; uv_rwlock_t Workers::m_rwlock;
uv_timer_t Workers::m_timer; uv_timer_t *Workers::m_timer = nullptr;
xmrig::Controller *Workers::m_controller = nullptr; xmrig::Controller *Workers::m_controller = nullptr;
@ -103,11 +104,11 @@ void Workers::printHashrate(bool detail)
char num2[8] = { 0 }; char num2[8] = { 0 };
char num3[8] = { 0 }; char num3[8] = { 0 };
Log::i()->text("%s| THREAD | AFFINITY | 10s H/s | 60s H/s | 15m H/s |", isColors ? "\x1B[1;37m" : ""); xmrig::Log::i()->text("%s| THREAD | AFFINITY | 10s H/s | 60s H/s | 15m H/s |", isColors ? "\x1B[1;37m" : "");
size_t i = 0; size_t i = 0;
for (const xmrig::IThread *thread : m_controller->config()->threads()) { for (const xmrig::IThread *thread : m_controller->config()->threads()) {
Log::i()->text("| %6zu | %8" PRId64 " | %7s | %7s | %7s |", xmrig::Log::i()->text("| %6zu | %8" PRId64 " | %7s | %7s | %7s |",
thread->index(), thread->index(),
thread->affinity(), thread->affinity(),
Hashrate::format(m_hashrate->calc(thread->index(), Hashrate::ShortInterval), num1, sizeof num1), Hashrate::format(m_hashrate->calc(thread->index(), Hashrate::ShortInterval), num1, sizeof num1),
@ -192,14 +193,17 @@ void Workers::start(xmrig::Controller *controller)
m_sequence = 1; m_sequence = 1;
m_paused = 1; m_paused = 1;
uv_async_init(uv_default_loop(), &m_async, Workers::onResult); m_async = new uv_async_t;
uv_timer_init(uv_default_loop(), &m_timer); uv_async_init(uv_default_loop(), m_async, Workers::onResult);
uv_timer_start(&m_timer, Workers::onTick, 500, 500);
m_timer = new uv_timer_t;
uv_timer_init(uv_default_loop(), m_timer);
uv_timer_start(m_timer, Workers::onTick, 500, 500);
uint32_t offset = 0; uint32_t offset = 0;
for (xmrig::IThread *thread : threads) { for (xmrig::IThread *thread : threads) {
Handle *handle = new Handle(thread, offset, m_status.ways); ThreadHandle *handle = new ThreadHandle(thread, offset, m_status.ways);
offset += thread->multiway(); offset += thread->multiway();
m_workers.push_back(handle); m_workers.push_back(handle);
@ -212,10 +216,10 @@ void Workers::start(xmrig::Controller *controller)
void Workers::stop() void Workers::stop()
{ {
uv_timer_stop(&m_timer); xmrig::Handle::close(m_timer);
xmrig::Handle::close(m_async);
m_hashrate->stop(); m_hashrate->stop();
uv_close(reinterpret_cast<uv_handle_t*>(&m_async), nullptr);
m_paused = 0; m_paused = 0;
m_sequence = 0; m_sequence = 0;
@ -231,7 +235,7 @@ void Workers::submit(const xmrig::JobResult &result)
m_queue.push_back(result); m_queue.push_back(result);
uv_mutex_unlock(&m_mutex); uv_mutex_unlock(&m_mutex);
uv_async_send(&m_async); uv_async_send(m_async);
} }
@ -257,7 +261,7 @@ void Workers::threadsSummary(rapidjson::Document &doc)
void Workers::onReady(void *arg) void Workers::onReady(void *arg)
{ {
auto handle = static_cast<Handle*>(arg); auto handle = static_cast<ThreadHandle*>(arg);
IWorker *worker = nullptr; IWorker *worker = nullptr;
@ -319,7 +323,7 @@ void Workers::onResult(uv_async_t *handle)
void Workers::onTick(uv_timer_t *handle) void Workers::onTick(uv_timer_t *handle)
{ {
for (Handle *handle : m_workers) { for (ThreadHandle *handle : m_workers) {
if (!handle->worker()) { if (!handle->worker()) {
return; return;
} }

View file

@ -36,9 +36,9 @@
#include "rapidjson/fwd.h" #include "rapidjson/fwd.h"
class Handle;
class Hashrate; class Hashrate;
class IWorker; class IWorker;
class ThreadHandle;
namespace xmrig { namespace xmrig {
@ -109,12 +109,12 @@ private:
static std::atomic<int> m_paused; static std::atomic<int> m_paused;
static std::atomic<uint64_t> m_sequence; static std::atomic<uint64_t> m_sequence;
static std::list<xmrig::JobResult> m_queue; static std::list<xmrig::JobResult> m_queue;
static std::vector<Handle*> m_workers; static std::vector<ThreadHandle*> m_workers;
static uint64_t m_ticks; static uint64_t m_ticks;
static uv_async_t m_async; static uv_async_t *m_async;
static uv_mutex_t m_mutex; static uv_mutex_t m_mutex;
static uv_rwlock_t m_rwlock; static uv_rwlock_t m_rwlock;
static uv_timer_t m_timer; static uv_timer_t *m_timer;
static xmrig::Controller *m_controller; static xmrig::Controller *m_controller;
}; };