/* XMRig * Copyright 2010 Jeff Garzik * Copyright 2012-2014 pooler * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018-2019 SChernykh * Copyright 2016-2019 XMRig , * * 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 . */ #include "backend/common/Threads.h" #include "backend/cpu/CpuThreads.h" #include "rapidjson/document.h" #ifdef XMRIG_FEATURE_OPENCL # include "backend/opencl/OclThreads.h" #endif namespace xmrig { static const char *kAsterisk = "*"; } // namespace xmrig template const T &xmrig::Threads::get(const String &profileName) const { static T empty; if (profileName.isNull() || !has(profileName)) { return empty; } return m_profiles.at(profileName); } template size_t xmrig::Threads::read(const rapidjson::Value &value) { using namespace rapidjson; for (auto &member : value.GetObject()) { if (member.value.IsArray() || member.value.IsObject()) { T threads(member.value); if (!threads.isEmpty()) { move(member.name.GetString(), std::move(threads)); } continue; } const Algorithm algo(member.name.GetString()); if (!algo.isValid()) { continue; } if (member.value.IsBool() && member.value.IsFalse()) { disable(algo); continue; } if (member.value.IsString()) { if (has(member.value.GetString())) { m_aliases.insert({ algo, member.value.GetString() }); } else { m_disabled.insert(algo); } } } return m_profiles.size(); } template xmrig::String xmrig::Threads::profileName(const Algorithm &algorithm, bool strict) const { if (isDisabled(algorithm)) { return String(); } const String name = algorithm.shortName(); if (has(name)) { return name; } if (m_aliases.count(algorithm) > 0) { return m_aliases.at(algorithm); } if (strict) { return String(); } if (name.contains("/")) { const String base = name.split('/').at(0); if (has(base)) { return base; } } if (has(kAsterisk)) { return kAsterisk; } return String(); } template void xmrig::Threads::toJSON(rapidjson::Value &out, rapidjson::Document &doc) const { using namespace rapidjson; auto &allocator = doc.GetAllocator(); for (const auto &kv : m_profiles) { out.AddMember(kv.first.toJSON(), kv.second.toJSON(doc), allocator); } for (const Algorithm &algo : m_disabled) { out.AddMember(StringRef(algo.shortName()), false, allocator); } for (const auto &kv : m_aliases) { out.AddMember(StringRef(kv.first.shortName()), kv.second.toJSON(), allocator); } } namespace xmrig { template class Threads; #ifdef XMRIG_FEATURE_OPENCL template class Threads; #endif } // namespace xmrig