From 6bd101c7e669f0397c3386eb0df02ce0571395df Mon Sep 17 00:00:00 2001 From: Chris Cannam Date: Mon, 26 Nov 2007 12:03:43 +0000 Subject: [PATCH] * Add OS/X CPU counter, fix mp "cacher" --- src/sysutils.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/sysutils.cpp b/src/sysutils.cpp index 6ac481a..d384ad6 100644 --- a/src/sysutils.cpp +++ b/src/sysutils.cpp @@ -25,13 +25,22 @@ system_is_multiprocessor() static bool tested = false, mp = false; if (tested) return mp; + int count = 0; - //... +#ifdef __APPLE__ + + size_t sz = sizeof(count); + if (sysctlbyname("hw.ncpu", &count, &sz, NULL, 0)) { + mp = false; + } else { + mp = (count > 1); + } + +#else FILE *cpuinfo = fopen("/proc/cpuinfo", "r"); if (!cpuinfo) return false; - int count = 0; char buf[256]; while (!feof(cpuinfo)) { fgets(buf, 256, cpuinfo); @@ -40,10 +49,13 @@ system_is_multiprocessor() } if (count > 1) break; } - fclose(cpuinfo); - return (count > 1); +#endif + + mp = (count > 1); + tested = true; + return mp; } }