-From: David Schleef <ds@ginger.bigkitten.com>
-Date: Tue, 10 Jun 2008 18:48:06 +0000 (-0700)
-Subject: [core] Check number of processors correctly on OS/X. Patch from
-X-Git-Url: http://diracvideo.org/git?p=schroedinger.git;a=commitdiff_plain;h=7e125aa636e520393ebf8e9315d3956e399f4175
-
-[core] Check number of processors correctly on OS/X. Patch from
-Karl Rasche <karlrasche@gmail.com>
----
-
-diff --git a/schroedinger/schroasync-pthread.c b/schroedinger/schroasync-pthread.c
-index 3a975e0..60bf1c1 100644
---- a/schroedinger/schroasync-pthread.c
-+++ b/schroedinger/schroasync-pthread.c
-@@ -13,6 +13,10 @@
- #include <sys/time.h>
- #include <time.h>
-
-+#ifdef __APPLE__
-+#include <sys/sysctl.h>
-+#endif
-+
- enum {
- STATE_IDLE,
- STATE_BUSY,
-@@ -79,14 +83,23 @@ schro_async_new(int n_threads,
- }
- }
- if (n_threads == 0) {
--#ifndef _WIN32
-- n_threads = sysconf(_SC_NPROCESSORS_CONF);
--#else
-+#ifdef _WIN32
- const char *s = getenv("NUMBER_OF_PROCESSORS");
- if (s) {
- n_threads = atoi(s);
- }
--#endif
-+#elif defined __APPLE__
-+ {
-+ int mib[] = {CTL_HW, HW_NCPU};
-+ size_t dataSize = sizeof(int);
-+
-+ if (sysctl(mib, 2, &n_threads, &dataSize, NULL, 0)) {
-+ n_threads = 0;
-+ }
-+ }
-+#else
-+ n_threads = sysconf(_SC_NPROCESSORS_CONF);
-+#endif
- }
- if (n_threads == 0) {
- n_threads = 1;