From 1a311302675102b8d695cfae6d1d171b89e7f58e Mon Sep 17 00:00:00 2001 From: James Cherry Date: Tue, 4 Jan 2022 09:51:07 -0700 Subject: [PATCH] machine Signed-off-by: James Cherry --- include/sta/Machine.hh | 11 +++++++---- util/Machine.cc | 2 +- util/MachineApple.cc | 7 ++----- util/MachineLinux.cc | 7 ++----- util/MachineWin32.cc | 8 -------- 5 files changed, 12 insertions(+), 23 deletions(-) diff --git a/include/sta/Machine.hh b/include/sta/Machine.hh index 5b826432..41d63dca 100644 --- a/include/sta/Machine.hh +++ b/include/sta/Machine.hh @@ -47,10 +47,13 @@ #if defined(_WINDOWS) || defined(_WIN32) #include + #include #define va_copy(d,s) ((d)=(s)) - #define strcasecmp _stricmp - #define strncasecmp strncmp - #define strtoull _strtoui64 + #ifndef __GNUC__ + #define strcasecmp _stricmp + #define strncasecmp strncmp + #define strtoull _strtoui64 + #endif // Flex doesn't check for unistd.h. #define YY_NO_UNISTD_H namespace sta { @@ -59,7 +62,7 @@ } #else #define vsnprint vsnprintf -#endif // _WINDOWS +#endif #include // size_t diff --git a/util/Machine.cc b/util/Machine.cc index 9667bc7a..2baf8613 100644 --- a/util/Machine.cc +++ b/util/Machine.cc @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#if defined(WIN32) +#if defined(_WIN32) #include "MachineWin32.cc" #elif defined(__APPLE__) #include "MachineApple.cc" diff --git a/util/MachineApple.cc b/util/MachineApple.cc index 8014992b..0b5f1636 100644 --- a/util/MachineApple.cc +++ b/util/MachineApple.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include "StaConfig.hh" #include "StringUtil.hh" @@ -32,11 +33,7 @@ static struct timeval elapsed_begin_time_; int processorCount() { -#if HAVE_PTHREAD_H - return sysconf(_SC_NPROCESSORS_CONF); -#else - return 1; -#endif + return std::thread::hardware_concurrency(); } void diff --git a/util/MachineLinux.cc b/util/MachineLinux.cc index e9ab21b6..afc573b9 100644 --- a/util/MachineLinux.cc +++ b/util/MachineLinux.cc @@ -21,6 +21,7 @@ #include #include #include +#include #include "StaConfig.hh" #include "StringUtil.hh" @@ -32,11 +33,7 @@ static struct timeval elapsed_begin_time_; int processorCount() { -#if HAVE_PTHREAD_H - return sysconf(_SC_NPROCESSORS_CONF); -#else - return 1; -#endif + return std::thread::hardware_concurrency(); } void diff --git a/util/MachineWin32.cc b/util/MachineWin32.cc index 361752cf..7b7542a8 100644 --- a/util/MachineWin32.cc +++ b/util/MachineWin32.cc @@ -11,8 +11,6 @@ #include #include // GetSystemInfo -#include "StaConfig.hh" // HAVE_PTHREAD_H - namespace sta { // Windows returns -1 if the string does not fit rather than the @@ -63,13 +61,7 @@ vasprintf(char **str, int processorCount() { -#if HAVE_PTHREAD_H - SYSTEM_INFO info; - GetSystemInfo(&info); - return info.dwNumberOfProcessors; -#else return 1; -#endif } void