Optimized RandomX initialization and switching.

This commit is contained in:
XMRig 2019-08-01 20:37:05 +07:00
parent ab0d3b8919
commit 84ff8af4bd
9 changed files with 156 additions and 157 deletions

View file

@ -31,6 +31,7 @@
#include <algorithm>
#include <mutex>
#include <string.h>
#include <string>
#include <time.h>
@ -69,14 +70,11 @@ public:
inline LogPrivate() :
m_buf()
{
uv_mutex_init(&m_mutex);
}
inline ~LogPrivate()
{
uv_mutex_destroy(&m_mutex);
for (ILogBackend *backend : m_backends) {
delete backend;
}
@ -91,13 +89,14 @@ public:
size_t size = 0;
size_t offset = 0;
lock();
std::lock_guard<std::mutex> lock(m_mutex);
timestamp(level, size, offset);
color(level, size);
const int rc = vsnprintf(m_buf + size, sizeof (m_buf) - offset - 32, fmt, args);
if (rc < 0) {
return unlock();
return;
}
size += std::min(static_cast<size_t>(rc), sizeof (m_buf) - offset - 32);
@ -119,16 +118,10 @@ public:
fputs(txt.c_str(), stdout);
fflush(stdout);
}
unlock();
}
private:
inline void lock() { uv_mutex_lock(&m_mutex); }
inline void unlock() { uv_mutex_unlock(&m_mutex); }
inline void timestamp(Log::Level level, size_t &size, size_t &offset)
{
if (level == Log::NONE) {
@ -192,8 +185,8 @@ private:
char m_buf[4096];
std::mutex m_mutex;
std::vector<ILogBackend*> m_backends;
uv_mutex_t m_mutex;
};

View file

@ -43,17 +43,20 @@ public:
~Buffer();
inline char *data() { return m_data; }
inline const char *data() const { return m_data; }
inline size_t size() const { return m_size; }
inline void from(const Buffer &other) { from(other.data(), other.size()); }
inline bool isEqual(const Buffer &other) const { return m_size == other.m_size && (m_size == 0 || memcmp(m_data, other.m_data, m_size) == 0); }
inline char *data() { return m_data; }
inline const char *data() const { return m_data; }
inline size_t size() const { return m_size; }
inline void from(const Buffer &other) { from(other.data(), other.size()); }
void from(const char *data, size_t size);
inline Buffer &operator=(const Buffer &other) { from(other); return *this; }
inline Buffer &operator=(Buffer &&other) { move(std::move(other)); return *this; }
inline bool operator!=(const Buffer &other) const { return !isEqual(other); }
inline bool operator==(const Buffer &other) const { return isEqual(other); }
inline Buffer &operator=(Buffer &&other) { move(std::move(other)); return *this; }
inline Buffer &operator=(const Buffer &other) { from(other); return *this; }
static Buffer allocUnsafe(size_t size);