mirror of
https://github.com/xmrig/xmrig.git
synced 2025-12-24 21:32:47 -05:00
replace new/delete with sp
This commit is contained in:
@@ -49,18 +49,12 @@ xmrig::MemoryPool::MemoryPool(size_t size, bool hugePages, uint32_t node)
|
||||
|
||||
constexpr size_t alignment = 1 << 24;
|
||||
|
||||
m_memory = new VirtualMemory(size * pageSize + alignment, hugePages, false, false, node);
|
||||
m_memory = std::make_shared<VirtualMemory>(size * pageSize + alignment, hugePages, false, false, node);
|
||||
|
||||
m_alignOffset = (alignment - (((size_t)m_memory->scratchpad()) % alignment)) % alignment;
|
||||
}
|
||||
|
||||
|
||||
xmrig::MemoryPool::~MemoryPool()
|
||||
{
|
||||
delete m_memory;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::MemoryPool::isHugePages(uint32_t) const
|
||||
{
|
||||
return m_memory && m_memory->isHugePages();
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(MemoryPool)
|
||||
|
||||
MemoryPool(size_t size, bool hugePages, uint32_t node = 0);
|
||||
~MemoryPool() override;
|
||||
~MemoryPool() override = default;
|
||||
|
||||
protected:
|
||||
bool isHugePages(uint32_t node) const override;
|
||||
@@ -55,7 +55,7 @@ private:
|
||||
size_t m_refs = 0;
|
||||
size_t m_offset = 0;
|
||||
size_t m_alignOffset = 0;
|
||||
VirtualMemory *m_memory = nullptr;
|
||||
std::shared_ptr<VirtualMemory> m_memory;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -42,14 +42,6 @@ xmrig::NUMAMemoryPool::NUMAMemoryPool(size_t size, bool hugePages) :
|
||||
}
|
||||
|
||||
|
||||
xmrig::NUMAMemoryPool::~NUMAMemoryPool()
|
||||
{
|
||||
for (auto kv : m_map) {
|
||||
delete kv.second;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::NUMAMemoryPool::isHugePages(uint32_t node) const
|
||||
{
|
||||
if (!m_size) {
|
||||
@@ -81,7 +73,7 @@ void xmrig::NUMAMemoryPool::release(uint32_t node)
|
||||
|
||||
xmrig::IMemoryPool *xmrig::NUMAMemoryPool::get(uint32_t node) const
|
||||
{
|
||||
return m_map.count(node) ? m_map.at(node) : nullptr;
|
||||
return m_map.count(node) ? m_map.at(node).get() : nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -89,8 +81,9 @@ xmrig::IMemoryPool *xmrig::NUMAMemoryPool::getOrCreate(uint32_t node) const
|
||||
{
|
||||
auto pool = get(node);
|
||||
if (!pool) {
|
||||
pool = new MemoryPool(m_nodeSize, m_hugePages, node);
|
||||
m_map.insert({ node, pool });
|
||||
auto new_pool = std::make_shared<MemoryPool>(m_nodeSize, m_hugePages, node);
|
||||
m_map.emplace(node, new_pool);
|
||||
pool = new_pool.get();
|
||||
}
|
||||
|
||||
return pool;
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(NUMAMemoryPool)
|
||||
|
||||
NUMAMemoryPool(size_t size, bool hugePages);
|
||||
~NUMAMemoryPool() override;
|
||||
~NUMAMemoryPool() override = default;
|
||||
|
||||
protected:
|
||||
bool isHugePages(uint32_t node) const override;
|
||||
@@ -61,7 +61,7 @@ private:
|
||||
bool m_hugePages = true;
|
||||
size_t m_nodeSize = 0;
|
||||
size_t m_size = 0;
|
||||
mutable std::map<uint32_t, IMemoryPool *> m_map;
|
||||
mutable std::map<uint32_t, std::shared_ptr<IMemoryPool>> m_map;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace xmrig {
|
||||
|
||||
|
||||
size_t VirtualMemory::m_hugePageSize = VirtualMemory::kDefaultHugePageSize;
|
||||
static IMemoryPool *pool = nullptr;
|
||||
static std::shared_ptr<IMemoryPool> pool;
|
||||
static std::mutex mutex;
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ uint32_t xmrig::VirtualMemory::bindToNUMANode(int64_t)
|
||||
|
||||
void xmrig::VirtualMemory::destroy()
|
||||
{
|
||||
delete pool;
|
||||
pool.reset();
|
||||
}
|
||||
|
||||
|
||||
@@ -125,10 +125,10 @@ void xmrig::VirtualMemory::init(size_t poolSize, size_t hugePageSize)
|
||||
|
||||
# ifdef XMRIG_FEATURE_HWLOC
|
||||
if (Cpu::info()->nodes() > 1) {
|
||||
pool = new NUMAMemoryPool(align(poolSize, Cpu::info()->nodes()), hugePageSize > 0);
|
||||
pool = std::make_shared<NUMAMemoryPool>(align(poolSize, Cpu::info()->nodes()), hugePageSize > 0);
|
||||
} else
|
||||
# endif
|
||||
{
|
||||
pool = new MemoryPool(poolSize, hugePageSize > 0);
|
||||
pool = std::make_shared<MemoryPool>(poolSize, hugePageSize > 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,7 +312,7 @@ void benchmark()
|
||||
constexpr uint32_t N = 1U << 21;
|
||||
|
||||
VirtualMemory::init(0, N);
|
||||
VirtualMemory* memory = new VirtualMemory(N * 8, true, false, false);
|
||||
std::shared_ptr<VirtualMemory> memory = std::make_shared<VirtualMemory>(N * 8, true, false, false);
|
||||
|
||||
// 2 MB cache per core by default
|
||||
size_t max_scratchpad_size = 1U << 21;
|
||||
@@ -438,7 +438,6 @@ void benchmark()
|
||||
delete helper;
|
||||
|
||||
CnCtx::release(ctx, 8);
|
||||
delete memory;
|
||||
});
|
||||
|
||||
t.join();
|
||||
|
||||
@@ -38,17 +38,6 @@ std::mutex KPCache::s_cacheMutex;
|
||||
KPCache KPCache::s_cache;
|
||||
|
||||
|
||||
KPCache::KPCache()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
KPCache::~KPCache()
|
||||
{
|
||||
delete m_memory;
|
||||
}
|
||||
|
||||
|
||||
bool KPCache::init(uint32_t epoch)
|
||||
{
|
||||
if (epoch >= sizeof(cache_sizes) / sizeof(cache_sizes[0])) {
|
||||
@@ -63,8 +52,7 @@ bool KPCache::init(uint32_t epoch)
|
||||
|
||||
const size_t size = cache_sizes[epoch];
|
||||
if (!m_memory || m_memory->size() < size) {
|
||||
delete m_memory;
|
||||
m_memory = new VirtualMemory(size, false, false, false);
|
||||
m_memory = std::make_shared<VirtualMemory>(size, false, false, false);
|
||||
}
|
||||
|
||||
const ethash_h256_t seedhash = ethash_get_seedhash(epoch);
|
||||
|
||||
@@ -41,8 +41,8 @@ public:
|
||||
|
||||
XMRIG_DISABLE_COPY_MOVE(KPCache)
|
||||
|
||||
KPCache();
|
||||
~KPCache();
|
||||
KPCache() = default;
|
||||
~KPCache() = default;
|
||||
|
||||
bool init(uint32_t epoch);
|
||||
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
static KPCache s_cache;
|
||||
|
||||
private:
|
||||
VirtualMemory* m_memory = nullptr;
|
||||
std::shared_ptr<VirtualMemory> m_memory;
|
||||
size_t m_size = 0;
|
||||
uint32_t m_epoch = 0xFFFFFFFFUL;
|
||||
std::vector<uint32_t> m_DAGCache;
|
||||
|
||||
@@ -40,7 +40,7 @@ class RxPrivate;
|
||||
|
||||
|
||||
static bool osInitialized = false;
|
||||
static RxPrivate *d_ptr = nullptr;
|
||||
static std::shared_ptr<RxPrivate> d_ptr;
|
||||
|
||||
|
||||
class RxPrivate
|
||||
@@ -73,15 +73,13 @@ void xmrig::Rx::destroy()
|
||||
RxMsr::destroy();
|
||||
# endif
|
||||
|
||||
delete d_ptr;
|
||||
|
||||
d_ptr = nullptr;
|
||||
d_ptr.reset();
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Rx::init(IRxListener *listener)
|
||||
{
|
||||
d_ptr = new RxPrivate(listener);
|
||||
d_ptr = std::make_shared<RxPrivate>(listener);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -44,8 +44,8 @@ public:
|
||||
inline ~RxBasicStoragePrivate() { deleteDataset(); }
|
||||
|
||||
inline bool isReady(const Job &job) const { return m_ready && m_seed == job; }
|
||||
inline RxDataset *dataset() const { return m_dataset; }
|
||||
inline void deleteDataset() { delete m_dataset; m_dataset = nullptr; }
|
||||
inline RxDataset *dataset() const { return m_dataset.get(); }
|
||||
inline void deleteDataset() { m_dataset.reset(); }
|
||||
|
||||
|
||||
inline void setSeed(const RxSeed &seed)
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
{
|
||||
const uint64_t ts = Chrono::steadyMSecs();
|
||||
|
||||
m_dataset = new RxDataset(hugePages, oneGbPages, true, mode, 0);
|
||||
m_dataset = std::make_shared<RxDataset>(hugePages, oneGbPages, true, mode, 0);
|
||||
if (!m_dataset->cache()->get()) {
|
||||
deleteDataset();
|
||||
|
||||
@@ -117,7 +117,7 @@ private:
|
||||
|
||||
|
||||
bool m_ready = false;
|
||||
RxDataset *m_dataset = nullptr;
|
||||
std::shared_ptr<RxDataset> m_dataset;
|
||||
RxSeed m_seed;
|
||||
};
|
||||
|
||||
@@ -133,7 +133,6 @@ xmrig::RxBasicStorage::RxBasicStorage() :
|
||||
|
||||
xmrig::RxBasicStorage::~RxBasicStorage()
|
||||
{
|
||||
delete d_ptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ protected:
|
||||
void init(const RxSeed &seed, uint32_t threads, bool hugePages, bool oneGbPages, RxConfig::Mode mode, int priority) override;
|
||||
|
||||
private:
|
||||
RxBasicStoragePrivate *d_ptr;
|
||||
std::shared_ptr<RxBasicStoragePrivate> d_ptr;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ static_assert(RANDOMX_FLAG_JIT == 8, "RANDOMX_FLAG_JIT flag mismatch");
|
||||
|
||||
xmrig::RxCache::RxCache(bool hugePages, uint32_t nodeId)
|
||||
{
|
||||
m_memory = new VirtualMemory(maxSize(), hugePages, false, false, nodeId);
|
||||
m_memory = std::make_shared<VirtualMemory>(maxSize(), hugePages, false, false, nodeId);
|
||||
|
||||
create(m_memory->raw());
|
||||
}
|
||||
@@ -50,8 +50,6 @@ xmrig::RxCache::RxCache(uint8_t *memory)
|
||||
xmrig::RxCache::~RxCache()
|
||||
{
|
||||
randomx_release_cache(m_cache);
|
||||
|
||||
delete m_memory;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ private:
|
||||
bool m_jit = true;
|
||||
Buffer m_seed;
|
||||
randomx_cache *m_cache = nullptr;
|
||||
VirtualMemory *m_memory = nullptr;
|
||||
std::shared_ptr<VirtualMemory> m_memory;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -79,10 +79,7 @@ xmrig::RxDataset::RxDataset(RxCache *cache) :
|
||||
|
||||
xmrig::RxDataset::~RxDataset()
|
||||
{
|
||||
randomx_release_dataset(m_dataset);
|
||||
|
||||
delete m_cache;
|
||||
delete m_memory;
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +104,7 @@ bool xmrig::RxDataset::init(const Buffer &seed, uint32_t numThreads, int priorit
|
||||
for (uint64_t i = 0; i < numThreads; ++i) {
|
||||
const uint32_t a = (datasetItemCount * i) / numThreads;
|
||||
const uint32_t b = (datasetItemCount * (i + 1)) / numThreads;
|
||||
threads.emplace_back(init_dataset_wrapper, m_dataset, m_cache->get(), a, b - a, priority);
|
||||
threads.emplace_back(init_dataset_wrapper, m_dataset.get(), m_cache->get(), a, b - a, priority);
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < numThreads; ++i) {
|
||||
@@ -115,7 +112,7 @@ bool xmrig::RxDataset::init(const Buffer &seed, uint32_t numThreads, int priorit
|
||||
}
|
||||
}
|
||||
else {
|
||||
init_dataset_wrapper(m_dataset, m_cache->get(), 0, datasetItemCount, priority);
|
||||
init_dataset_wrapper(m_dataset.get(), m_cache->get(), 0, datasetItemCount, priority);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -180,7 +177,7 @@ uint8_t *xmrig::RxDataset::tryAllocateScrathpad()
|
||||
|
||||
void *xmrig::RxDataset::raw() const
|
||||
{
|
||||
return m_dataset ? randomx_get_dataset_memory(m_dataset) : nullptr;
|
||||
return m_dataset ? randomx_get_dataset_memory(m_dataset.get()) : nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -191,7 +188,7 @@ void xmrig::RxDataset::setRaw(const void *raw)
|
||||
}
|
||||
|
||||
volatile size_t N = maxSize();
|
||||
memcpy(randomx_get_dataset_memory(m_dataset), raw, N);
|
||||
memcpy(randomx_get_dataset_memory(m_dataset.get()), raw, N);
|
||||
}
|
||||
|
||||
|
||||
@@ -199,24 +196,22 @@ void xmrig::RxDataset::allocate(bool hugePages, bool oneGbPages)
|
||||
{
|
||||
if (m_mode == RxConfig::LightMode) {
|
||||
LOG_ERR(CLEAR "%s" RED_BOLD_S "fast RandomX mode disabled by config", Tags::randomx());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_mode == RxConfig::AutoMode && uv_get_total_memory() < (maxSize() + RxCache::maxSize())) {
|
||||
LOG_ERR(CLEAR "%s" RED_BOLD_S "not enough memory for RandomX dataset", Tags::randomx());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
m_memory = new VirtualMemory(maxSize(), hugePages, oneGbPages, false, m_node);
|
||||
m_memory = std::make_shared<VirtualMemory>(maxSize(), hugePages, oneGbPages, false, m_node);
|
||||
|
||||
if (m_memory->isOneGbPages()) {
|
||||
m_scratchpadOffset = maxSize() + RANDOMX_CACHE_MAX_SIZE;
|
||||
m_scratchpadLimit = m_memory->capacity();
|
||||
}
|
||||
|
||||
m_dataset = randomx_create_dataset(m_memory->raw());
|
||||
m_dataset = std::shared_ptr<randomx_dataset>(randomx_create_dataset(m_memory->raw()), randomx_release_dataset);
|
||||
|
||||
# ifdef XMRIG_OS_LINUX
|
||||
if (oneGbPages && !isOneGbPages()) {
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
RxDataset(RxCache *cache);
|
||||
~RxDataset();
|
||||
|
||||
inline randomx_dataset *get() const { return m_dataset; }
|
||||
inline randomx_dataset *get() const { return m_dataset.get(); }
|
||||
inline RxCache *cache() const { return m_cache; }
|
||||
inline void setCache(RxCache *cache) { m_cache = cache; }
|
||||
|
||||
@@ -70,11 +70,11 @@ private:
|
||||
|
||||
const RxConfig::Mode m_mode = RxConfig::FastMode;
|
||||
const uint32_t m_node;
|
||||
randomx_dataset *m_dataset = nullptr;
|
||||
std::shared_ptr<randomx_dataset> m_dataset;
|
||||
RxCache *m_cache = nullptr;
|
||||
size_t m_scratchpadLimit = 0;
|
||||
std::atomic<size_t> m_scratchpadOffset{};
|
||||
VirtualMemory *m_memory = nullptr;
|
||||
std::shared_ptr<VirtualMemory> m_memory;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -49,8 +49,6 @@ xmrig::RxQueue::~RxQueue()
|
||||
m_cv.notify_one();
|
||||
|
||||
m_thread.join();
|
||||
|
||||
delete m_storage;
|
||||
}
|
||||
|
||||
|
||||
@@ -90,12 +88,12 @@ void xmrig::RxQueue::enqueue(const RxSeed &seed, const std::vector<uint32_t> &no
|
||||
if (!m_storage) {
|
||||
# ifdef XMRIG_FEATURE_HWLOC
|
||||
if (!nodeset.empty()) {
|
||||
m_storage = new RxNUMAStorage(nodeset);
|
||||
m_storage = std::make_shared<RxNUMAStorage>(nodeset);
|
||||
}
|
||||
else
|
||||
# endif
|
||||
{
|
||||
m_storage = new RxBasicStorage();
|
||||
m_storage = std::make_shared<RxBasicStorage>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ private:
|
||||
void onReady();
|
||||
|
||||
IRxListener *m_listener = nullptr;
|
||||
IRxStorage *m_storage = nullptr;
|
||||
std::shared_ptr<IRxStorage> m_storage;
|
||||
RxSeed m_seed;
|
||||
State m_state = STATE_IDLE;
|
||||
std::condition_variable m_cv;
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include "crypto/rx/RxVm.h"
|
||||
|
||||
|
||||
randomx_vm *xmrig::RxVm::create(RxDataset *dataset, uint8_t *scratchpad, bool softAes, const Assembly &assembly, uint32_t node)
|
||||
std::shared_ptr<randomx_vm> xmrig::RxVm::create(RxDataset *dataset, uint8_t *scratchpad, bool softAes, const Assembly &assembly, uint32_t node)
|
||||
{
|
||||
int flags = 0;
|
||||
|
||||
@@ -46,13 +46,8 @@ randomx_vm *xmrig::RxVm::create(RxDataset *dataset, uint8_t *scratchpad, bool so
|
||||
flags |= RANDOMX_FLAG_AMD;
|
||||
}
|
||||
|
||||
return randomx_create_vm(static_cast<randomx_flags>(flags), !dataset->get() ? dataset->cache()->get() : nullptr, dataset->get(), scratchpad, node);
|
||||
return std::shared_ptr<randomx_vm>(randomx_create_vm(
|
||||
static_cast<randomx_flags>(flags), !dataset->get() ? dataset->cache()->get() : nullptr, dataset->get(), scratchpad, node),
|
||||
randomx_destroy_vm);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::RxVm::destroy(randomx_vm* vm)
|
||||
{
|
||||
if (vm) {
|
||||
randomx_destroy_vm(vm);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,8 +38,7 @@ class RxDataset;
|
||||
class RxVm
|
||||
{
|
||||
public:
|
||||
static randomx_vm *create(RxDataset *dataset, uint8_t *scratchpad, bool softAes, const Assembly &assembly, uint32_t node);
|
||||
static void destroy(randomx_vm *vm);
|
||||
static std::shared_ptr<randomx_vm> create(RxDataset *dataset, uint8_t *scratchpad, bool softAes, const Assembly &assembly, uint32_t node);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user