mirror of
https://github.com/xmrig/xmrig.git
synced 2025-12-25 13:42:54 -05:00
Merge xmrig v6.4.0 into master
This commit is contained in:
98
src/base/io/Async.cpp
Normal file
98
src/base/io/Async.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2015-2020 libuv project contributors.
|
||||
* Copyright (c) 2020 cohcho <https://github.com/cohcho>
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 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 "base/io/Async.h"
|
||||
|
||||
|
||||
#if defined(XMRIG_UV_PERFORMANCE_BUG)
|
||||
#include <sys/eventfd.h>
|
||||
#include <sys/poll.h>
|
||||
#include <unistd.h>
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
uv_async_t::~uv_async_t()
|
||||
{
|
||||
close(m_fd);
|
||||
}
|
||||
|
||||
|
||||
static void on_schedule(uv_poll_t *handle, int status, int events)
|
||||
{
|
||||
static uint64_t val;
|
||||
uv_async_t *async = reinterpret_cast<uv_async_t *>(handle);
|
||||
for (;;) {
|
||||
int r = read(async->m_fd, &val, sizeof(val));
|
||||
|
||||
if (r == sizeof(val))
|
||||
continue;
|
||||
|
||||
if (r != -1)
|
||||
break;
|
||||
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK)
|
||||
break;
|
||||
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
|
||||
abort();
|
||||
}
|
||||
if (async->m_cb) {
|
||||
(*async->m_cb)(async);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int uv_async_init(uv_loop_t *loop, uv_async_t *async, uv_async_cb cb)
|
||||
{
|
||||
int fd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
|
||||
if (fd < 0) {
|
||||
return uv_translate_sys_error(errno);
|
||||
}
|
||||
uv_poll_init(loop, (uv_poll_t *)async, fd);
|
||||
uv_poll_start((uv_poll_t *)async, POLLIN, on_schedule);
|
||||
async->m_cb = cb;
|
||||
async->m_fd = fd;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int uv_async_send(uv_async_t *async)
|
||||
{
|
||||
static const uint64_t val = 1;
|
||||
int r;
|
||||
do {
|
||||
r = write(async->m_fd, &val, sizeof(val));
|
||||
}
|
||||
while (r == -1 && errno == EINTR);
|
||||
if (r == sizeof(val) || (r == 1 && (errno == EAGAIN || errno == EWOULDBLOCK))) {
|
||||
return 0;
|
||||
}
|
||||
abort();
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
#endif
|
||||
52
src/base/io/Async.h
Normal file
52
src/base/io/Async.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2015-2020 libuv project contributors.
|
||||
* Copyright (c) 2020 cohcho <https://github.com/cohcho>
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 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/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_ASYNC_H
|
||||
#define XMRIG_ASYNC_H
|
||||
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
// since 2019.05.16, Version 1.29.0 (Stable)
|
||||
#if (UV_VERSION_MAJOR >= 1) && (UV_VERSION_MINOR >= 29) && defined(__linux__)
|
||||
#define XMRIG_UV_PERFORMANCE_BUG
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
struct uv_async_t: uv_poll_t
|
||||
{
|
||||
typedef void (*uv_async_cb)(uv_async_t* handle);
|
||||
~uv_async_t();
|
||||
int m_fd = -1;
|
||||
uv_async_cb m_cb = nullptr;
|
||||
};
|
||||
|
||||
|
||||
using uv_async_cb = uv_async_t::uv_async_cb;
|
||||
extern int uv_async_init(uv_loop_t *loop, uv_async_t *async, uv_async_cb cb);
|
||||
extern int uv_async_send(uv_async_t *async);
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* XMRIG_ASYNC_H */
|
||||
@@ -104,6 +104,7 @@ private:
|
||||
#define WHITE_BOLD_S CSI "1;37m" // actually white
|
||||
|
||||
#define BRIGHT_BLACK_BG_S CSI "100m" // somewhat MD.GRAY
|
||||
#define RED_BG_BOLD_S CSI "41;1m"
|
||||
#define GREEN_BG_BOLD_S CSI "42;1m"
|
||||
#define YELLOW_BG_BOLD_S CSI "43;1m"
|
||||
#define BLUE_BG_S CSI "44m"
|
||||
@@ -132,6 +133,7 @@ private:
|
||||
#define WHITE_BOLD(x) WHITE_BOLD_S x CLEAR
|
||||
|
||||
#define BRIGHT_BLACK_BG(x) BRIGHT_BLACK_BG_S x CLEAR
|
||||
#define RED_BG_BOLD(x) RED_BG_BOLD_S x CLEAR
|
||||
#define GREEN_BG_BOLD(x) GREEN_BG_BOLD_S x CLEAR
|
||||
#define YELLOW_BG_BOLD(x) YELLOW_BG_BOLD_S x CLEAR
|
||||
#define BLUE_BG(x) BLUE_BG_S x CLEAR
|
||||
|
||||
@@ -70,6 +70,16 @@ const char *xmrig::Tags::randomx()
|
||||
return tag;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_BENCHMARK
|
||||
const char *xmrig::Tags::bench()
|
||||
{
|
||||
static const char *tag = GREEN_BG_BOLD(WHITE_BOLD_S " bench ");
|
||||
|
||||
return tag;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -40,6 +40,9 @@ public:
|
||||
# ifdef XMRIG_ALGO_RANDOMX
|
||||
static const char *randomx();
|
||||
# endif
|
||||
# ifdef XMRIG_FEATURE_BENCHMARK
|
||||
static const char *bench();
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
|
||||
Reference in New Issue
Block a user