From 28051387e91abefdecaba0ef7c38e62fe474e06b Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Sat, 4 Nov 2017 19:10:20 +0700 Subject: [PATCH] Code refactor: rewrite TxUtil::getNumberofProcessors() --- src/GLideNHQ/TxUtil.cpp | 35 +++-------------------------------- src/GLideNHQ/TxUtil.h | 2 +- 2 files changed, 4 insertions(+), 33 deletions(-) diff --git a/src/GLideNHQ/TxUtil.cpp b/src/GLideNHQ/TxUtil.cpp index c72aea4f..0a1e6b64 100644 --- a/src/GLideNHQ/TxUtil.cpp +++ b/src/GLideNHQ/TxUtil.cpp @@ -21,6 +21,7 @@ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include #include "TxUtil.h" #include "TxDbg.h" #include @@ -490,41 +491,11 @@ findmax0: return 1; } -int -TxUtil::getNumberofProcessors() +uint32 TxUtil::getNumberofProcessors() { - int numcore = 1; -#ifndef OS_ANDROID - try { -#if defined (OS_WINDOWS) - SYSTEM_INFO sysinfo; - GetSystemInfo(&sysinfo); - numcore = sysinfo.dwNumberOfProcessors; -#elif defined (OS_MAC_OS_X) - int nm[2]; - size_t len = 4; - uint32_t count; - - nm[0] = CTL_HW; nm[1] = HW_AVAILCPU; - sysctl(nm, 2, &count, &len, nullptr, 0); - - if (count < 1) { - nm[1] = HW_NCPU; - sysctl(nm, 2, &count, &len, nullptr, 0); - if (count < 1) { count = 1; } - } - numcore = count; -#elif defined (OS_LINUX) - numcore = sysconf(_SC_NPROCESSORS_ONLN); -#endif - } catch (...) { - DBG_INFO(80, wst("Error: number of processor detection failed!\n")); - } - + uint32 numcore = std::thread::hardware_concurrency(); if (numcore > MAX_NUMCORE) numcore = MAX_NUMCORE; -#endif // OS_ANDROID DBG_INFO(80, wst("Number of processors : %d\n"), numcore); - return numcore; } diff --git a/src/GLideNHQ/TxUtil.h b/src/GLideNHQ/TxUtil.h index 37638eac..aaa52776 100644 --- a/src/GLideNHQ/TxUtil.h +++ b/src/GLideNHQ/TxUtil.h @@ -50,7 +50,7 @@ public: #endif static uint32 checksum(uint8 *src, int width, int height, int size, int rowStride); static uint64 checksum64(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette); - static int getNumberofProcessors(); + static uint32 getNumberofProcessors(); }; class TxMemBuf