Code cleanup.

This commit is contained in:
XMRig 2023-06-06 23:15:58 +07:00
parent 554b60966b
commit a2ae17b4c4
No known key found for this signature in database
GPG key ID: 446A53638BE94409

View file

@ -90,7 +90,7 @@ CORE_HASH(14, whirlpool );
#undef CORE_HASH #undef CORE_HASH
typedef void (*core_hash_func)(const uint8_t* data, size_t size, uint8_t* output); using core_hash_func = void (*)(const uint8_t* data, size_t size, uint8_t* output);
static const core_hash_func core_hash[15] = { h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11, h12, h13, h14 }; static const core_hash_func core_hash[15] = { h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11, h12, h13, h14 };
namespace xmrig namespace xmrig
@ -169,6 +169,8 @@ static struct AlgoTune
struct HelperThread struct HelperThread
{ {
XMRIG_DISABLE_COPY_MOVE_DEFAULT(HelperThread)
HelperThread(hwloc_bitmap_t cpu_set, int priority, bool is8MB) : m_cpuSet(cpu_set), m_priority(priority), m_is8MB(is8MB) HelperThread(hwloc_bitmap_t cpu_set, int priority, bool is8MB) : m_cpuSet(cpu_set), m_priority(priority), m_is8MB(is8MB)
{ {
uv_mutex_init(&m_mutex); uv_mutex_init(&m_mutex);
@ -198,14 +200,17 @@ struct HelperThread
struct TaskBase struct TaskBase
{ {
virtual ~TaskBase() {} XMRIG_DISABLE_COPY_MOVE(TaskBase)
virtual void run() = 0;
TaskBase() = default;
virtual ~TaskBase() = default;
virtual void run() = 0;
}; };
template<typename T> template<typename T>
struct Task : TaskBase struct Task : TaskBase
{ {
inline Task(T&& task) : m_task(std::move(task)) explicit inline Task(T&& task) : m_task(std::move(task))
{ {
static_assert(sizeof(Task) <= 128, "Task struct is too large"); static_assert(sizeof(Task) <= 128, "Task struct is too large");
} }
@ -223,7 +228,7 @@ struct HelperThread
inline void launch_task(T&& task) inline void launch_task(T&& task)
{ {
uv_mutex_lock(&m_mutex); uv_mutex_lock(&m_mutex);
new (&m_tasks[m_numTasks++]) Task<T>(std::move(task)); new (&m_tasks[m_numTasks++]) Task<T>(std::forward<T>(task));
uv_cond_signal(&m_cond); uv_cond_signal(&m_cond);
uv_mutex_unlock(&m_mutex); uv_mutex_unlock(&m_mutex);
} }
@ -294,7 +299,7 @@ void benchmark()
hwloc_topology_t topology = reinterpret_cast<HwlocCpuInfo*>(Cpu::info())->topology(); hwloc_topology_t topology = reinterpret_cast<HwlocCpuInfo*>(Cpu::info())->topology();
hwloc_obj_t pu = hwloc_get_pu_obj_by_os_index(topology, thread_index1); hwloc_obj_t pu = hwloc_get_pu_obj_by_os_index(topology, thread_index1);
hwloc_obj_t pu2; hwloc_obj_t pu2 = nullptr;
hwloc_get_closest_objs(topology, pu, &pu2, 1); hwloc_get_closest_objs(topology, pu, &pu2, 1);
uint32_t thread_index2 = pu2 ? pu2->os_index : thread_index1; uint32_t thread_index2 = pu2 ? pu2->os_index : thread_index1;
@ -585,9 +590,13 @@ void hash_octa(const uint8_t* data, size_t size, uint8_t* output, cryptonight_ct
uint8_t tmp[64 * N]; uint8_t tmp[64 * N];
if (helper && (tune[cn_indices[0]].threads == 2) && (tune[cn_indices[1]].threads == 2) && (tune[cn_indices[2]].threads == 2)) { if (helper && (tune[cn_indices[0]].threads == 2) && (tune[cn_indices[1]].threads == 2) && (tune[cn_indices[2]].threads == 2)) {
const size_t n = N / 2; constexpr size_t n = N / 2;
helper->launch_task([av, data, size, &ctx_memory, ctx, &cn_indices, &core_indices, &tmp, output, tune]() {
# ifdef _MSC_VER
constexpr size_t n = N / 2;
# endif
helper->launch_task([n, av, data, size, &ctx_memory, ctx, &cn_indices, &core_indices, &tmp, output, tune]() {
const uint8_t* input = data; const uint8_t* input = data;
size_t input_size = size; size_t input_size = size;