Sync changes.

This commit is contained in:
XMRig 2018-11-20 07:24:14 +07:00
parent 9f6f599d78
commit 2a2712ab90
12 changed files with 114 additions and 33 deletions

View file

@ -4,8 +4,9 @@
* 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 2016-2017 XMRig <support@xmrig.com>
*
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2018 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
@ -36,7 +37,7 @@
char Platform::m_defaultConfigName[520] = { 0 };
xmrig::c_str Platform::m_userAgent;
xmrig::String Platform::m_userAgent;
const char *Platform::defaultConfigName()

View file

@ -4,8 +4,9 @@
* 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 2016-2017 XMRig <support@xmrig.com>
*
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2018 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
@ -28,7 +29,7 @@
#include <stdint.h>
#include "common/utils/c_str.h"
#include "base/tools/String.h"
class Platform
@ -36,7 +37,9 @@ class Platform
public:
static bool setThreadAffinity(uint64_t cpu_id);
static const char *defaultConfigName();
static uint32_t setTimerResolution(uint32_t resolution);
static void init(const char *userAgent);
static void restoreTimerResolution();
static void setProcessPriority(int priority);
static void setThreadPriority(int priority);
@ -46,7 +49,7 @@ private:
static char *createUserAgent();
static char m_defaultConfigName[520];
static xmrig::c_str m_userAgent;
static xmrig::String m_userAgent;
};

View file

@ -65,9 +65,19 @@ bool Platform::setThreadAffinity(uint64_t cpu_id)
}
uint32_t Platform::setTimerResolution(uint32_t resolution)
{
return resolution;
}
void Platform::restoreTimerResolution()
{
}
void Platform::setProcessPriority(int priority)
{
}

View file

@ -92,6 +92,17 @@ bool Platform::setThreadAffinity(uint64_t cpu_id)
}
uint32_t Platform::setTimerResolution(uint32_t resolution)
{
return resolution;
}
void Platform::restoreTimerResolution()
{
}
void Platform::setProcessPriority(int priority)
{
}

View file

@ -4,8 +4,9 @@
* 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 2016-2017 XMRig <support@xmrig.com>
*
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2018 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
@ -22,6 +23,7 @@
*/
#include <algorithm>
#include <winsock2.h>
#include <windows.h>
#include <uv.h>
@ -37,6 +39,9 @@
#endif
static uint32_t timerResolution = 0;
static inline OSVERSIONINFOEX winOsVersion()
{
typedef NTSTATUS (NTAPI *RtlGetVersionFunction)(LPOSVERSIONINFO);
@ -94,6 +99,34 @@ bool Platform::setThreadAffinity(uint64_t cpu_id)
}
uint32_t Platform::setTimerResolution(uint32_t resolution)
{
# ifdef XMRIG_AMD_PROJECT
TIMECAPS tc;
if (timeGetDevCaps(&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR) {
return 0;
}
timerResolution = std::min<uint32_t>(std::max<uint32_t>(tc.wPeriodMin, resolution), tc.wPeriodMax);
return timeBeginPeriod(timerResolution) == TIMERR_NOERROR ? timerResolution : 0;
# else
return resolution;
# endif
}
void Platform::restoreTimerResolution()
{
# ifdef XMRIG_AMD_PROJECT
if (timerResolution) {
timeEndPeriod(timerResolution);
}
# endif
}
void Platform::setProcessPriority(int priority)
{
if (priority == -1) {
@ -121,6 +154,7 @@ void Platform::setProcessPriority(int priority)
case 5:
prio = REALTIME_PRIORITY_CLASS;
break;
default:
break;

View file

@ -212,6 +212,10 @@ const char *Client::tlsVersion() const
int64_t Client::submit(const JobResult &result)
{
if (result.clientId != m_rpcId) {
return -1;
}
using namespace rapidjson;
# ifdef XMRIG_PROXY_PROJECT
@ -355,6 +359,8 @@ bool Client::parseJob(const rapidjson::Value &params, int *code)
return false;
}
m_job.setClientId(m_rpcId);
if (m_job != job) {
m_jobs++;
m_job = std::move(job);

View file

@ -21,8 +21,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __ID_H__
#define __ID_H__
#ifndef XMRIG_ID_H
#define XMRIG_ID_H
#include <string.h>
@ -95,4 +95,4 @@ private:
} /* namespace xmrig */
#endif /* __ID_H__ */
#endif /* XMRIG_ID_H */

View file

@ -91,6 +91,12 @@ Job::~Job()
}
bool Job::isEqual(const Job &other) const
{
return m_id == other.m_id && m_clientId == other.m_clientId && memcmp(m_blob, other.m_blob, sizeof(m_blob)) == 0;
}
bool Job::setBlob(const char *blob)
{
if (!blob) {
@ -214,18 +220,6 @@ char *Job::toHex(const unsigned char* in, unsigned int len)
#endif
bool Job::operator==(const Job &other) const
{
return m_id == other.m_id && memcmp(m_blob, other.m_blob, sizeof(m_blob)) == 0;
}
bool Job::operator!=(const Job &other) const
{
return m_id != other.m_id || memcmp(m_blob, other.m_blob, sizeof(m_blob)) != 0;
}
xmrig::Variant Job::variant() const
{
using namespace xmrig;

View file

@ -42,6 +42,7 @@ public:
Job(int poolId, bool nicehash, const xmrig::Algorithm &algorithm, const xmrig::Id &clientId);
~Job();
bool isEqual(const Job &other) const;
bool setBlob(const char *blob);
bool setTarget(const char *target);
void setAlgorithm(const char *algo);
@ -81,8 +82,8 @@ public:
static char *toHex(const unsigned char* in, unsigned int len);
# endif
bool operator==(const Job &other) const;
bool operator!=(const Job &other) const;
inline bool operator==(const Job &other) const { return isEqual(other); }
inline bool operator!=(const Job &other) const { return !isEqual(other); }
private:
xmrig::Variant variant() const;

View file

@ -31,7 +31,7 @@
namespace xmrig {
static inline int64_t currentMSecsSinceEpoch()
static inline int64_t steadyTimestamp()
{
using namespace std::chrono;
if (high_resolution_clock::is_steady) {
@ -42,6 +42,14 @@ static inline int64_t currentMSecsSinceEpoch()
}
static inline int64_t currentMSecsSinceEpoch()
{
using namespace std::chrono;
return time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count();
}
} /* namespace xmrig */
#endif /* XMRIG_TIMESTAMP_H */