From 130c32e7d46da7030f1d6285e3089e38b95fa050 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Tue, 7 Feb 2023 23:17:03 +0100 Subject: [PATCH] Include only sysinfoapi.h on Windows machine to reduce dependency Add fallback to _SC_NPROCESSORS_CONF if _SC_NPROCESSORS_ONLN is not supported (Android) --- m-worker.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/m-worker.h b/m-worker.h index 58a5c5e6..a58ab7a4 100644 --- a/m-worker.h +++ b/m-worker.h @@ -42,7 +42,7 @@ /* Include needed system header for detection of how many cores are available in the system */ #if defined(_WIN32) -# include +# include #elif (defined(__APPLE__) && defined(__MACH__)) \ || defined(__DragonFly__) || defined(__FreeBSD__) \ || defined(__NetBSD__) || defined(__OpenBSD__) @@ -174,7 +174,9 @@ typedef struct m_worker_sync_s { struct m_worker_s *worker; // Reference to the pool of workers } m_worker_sync_t[1]; -/* Return the number of cores available in the system */ +/* Return the number of CPU cores available in the system. + Works for WINDOWS, MACOS, *BSD, LINUX. + */ static inline int m_work3r_get_cpu_count(void) { @@ -193,6 +195,8 @@ m_work3r_get_cpu_count(void) return M_MAX(1, count); #elif defined (_SC_NPROCESSORS_ONLN) return (int) sysconf(_SC_NPROCESSORS_ONLN); +#elif defined (_SC_NPROCESSORS_CONF) + return (int) sysconf(_SC_NPROCESSORS_CONF); #else return 1; #endif