Added class CpuThreads.

This commit is contained in:
XMRig 2019-08-07 16:13:23 +07:00
parent 0adab95ce4
commit 96fd7545d1
12 changed files with 160 additions and 58 deletions

View file

@ -24,7 +24,7 @@
#include "backend/common/Threads.h"
#include "backend/cpu/CpuThread.h"
#include "backend/cpu/CpuThreads.h"
#include "rapidjson/document.h"
@ -38,9 +38,9 @@ static const char *kAsterisk = "*";
template <class T>
const std::vector<T> &xmrig::Threads<T>::get(const String &profileName) const
const T &xmrig::Threads<T>::get(const String &profileName) const
{
static std::vector<T> empty;
static T empty;
if (profileName.isNull() || !has(profileName)) {
return empty;
}
@ -56,16 +56,9 @@ size_t xmrig::Threads<T>::read(const rapidjson::Value &value)
for (auto &member : value.GetObject()) {
if (member.value.IsArray()) {
std::vector<T> threads;
T threads(member.value);
for (auto &v : member.value.GetArray()) {
T thread(v);
if (thread.isValid()) {
threads.push_back(std::move(thread));
}
}
if (!threads.empty()) {
if (!threads.isEmpty()) {
move(member.name.GetString(), std::move(threads));
}
@ -138,13 +131,7 @@ void xmrig::Threads<T>::toJSON(rapidjson::Value &out, rapidjson::Document &doc)
auto &allocator = doc.GetAllocator();
for (const auto &kv : m_profiles) {
Value arr(kArrayType);
for (const T &thread : kv.second) {
arr.PushBack(thread.toJSON(doc), allocator);
}
out.AddMember(kv.first.toJSON(), arr, allocator);
out.AddMember(kv.first.toJSON(), kv.second.toJSON(doc), allocator);
}
for (const Algorithm &algo : m_disabled) {
@ -159,6 +146,6 @@ void xmrig::Threads<T>::toJSON(rapidjson::Value &out, rapidjson::Document &doc)
namespace xmrig {
template class Threads<CpuThread>;
template class Threads<CpuThreads>;
} // namespace xmrig

View file

@ -45,18 +45,18 @@ public:
inline bool has(const char *profile) const { return m_profiles.count(profile) > 0; }
inline bool isDisabled(const Algorithm &algo) const { return m_disabled.count(algo) > 0; }
inline bool isExist(const Algorithm &algo) const { return isDisabled(algo) || m_aliases.count(algo) > 0 || has(algo.shortName()); }
inline const std::vector<T> &get(const Algorithm &algo, bool strict = false) const { return get(profileName(algo, strict)); }
inline const T &get(const Algorithm &algo, bool strict = false) const { return get(profileName(algo, strict)); }
inline void disable(const Algorithm &algo) { m_disabled.insert(algo); }
inline void move(const char *profile, std::vector<T> &&threads) { m_profiles.insert({ profile, threads }); }
inline void move(const char *profile, T &&threads) { m_profiles.insert({ profile, threads }); }
const std::vector<T> &get(const String &profileName) const;
const T &get(const String &profileName) const;
size_t read(const rapidjson::Value &value);
String profileName(const Algorithm &algorithm, bool strict = false) const;
void toJSON(rapidjson::Value &out, rapidjson::Document &doc) const;
private:
std::map<Algorithm, String> m_aliases;
std::map<String, std::vector<T> > m_profiles;
std::map<String, T> m_profiles;
std::set<Algorithm> m_disabled;
};