Implemented availableProcessors() for darwin.
authortwisti <none@none>
Fri, 12 Nov 2004 11:25:19 +0000 (11:25 +0000)
committertwisti <none@none>
Fri, 12 Nov 2004 11:25:19 +0000 (11:25 +0000)
nat/Runtime.c
src/native/vm/VMRuntime.c

index 880dcd95d8e1c67ff4a62529af9f6d461b9b5ae1..d6cbb0d833fdfca138014fe497aceb29b7e1d675 100644 (file)
@@ -29,7 +29,7 @@
    Changes: Joseph Wenninger
             Christian Thalinger
 
-   $Id: Runtime.c 1465 2004-11-08 11:09:01Z twisti $
+   $Id: Runtime.c 1487 2004-11-12 11:25:19Z twisti $
 
 */
 
 #include <dlfcn.h>
 #endif
 
+/* this should work on BSD */
+/*
+#if defined(__DARWIN__)
+#include <sys/sysctl.h>
+#endif
+*/
+
 #undef JOWENN_DEBUG
 
 /* should we run all finalizers on exit? */
 static bool finalizeOnExit = false;
 
-
 /* temporary property structure */
 
 typedef struct property property;
@@ -254,6 +260,33 @@ JNIEXPORT s4 JNICALL Java_java_lang_VMRuntime_availableProcessors(JNIEnv *env, j
 #elif defined(_SC_NPROCESSORS_ONLN)
        return (s4) sysconf(_SC_NPROCESSORS_ONLN);
 
+#elif defined(__DARWIN__)
+       /* this should work in BSD */
+       /*
+       int ncpu, mib[2], rc;
+       size_t len;
+
+       mib[0] = CTL_HW;
+       mib[1] = HW_NCPU;
+       len = sizeof(ncpu);
+       rc = sysctl(mib, 2, &ncpu, &len, NULL, 0);
+
+       return (s4) ncpu;
+       */
+
+       host_basic_info_data_t hinfo;
+       mach_msg_type_number_t hinfo_count = HOST_BASIC_INFO_COUNT;
+       kern_return_t rc;
+
+       rc = host_info(mach_host_self(), HOST_BASIC_INFO,
+                                  (host_info_t) &hinfo, &hinfo_count);
+       if (rc != KERN_SUCCESS) {
+               return -1;
+       }
+
+    return (s4) hinfo.avail_cpus;
+
 #else
        return 1;
 #endif
index 5eb0543503d04d732d2f6bc40a318fba84c5707d..13df6b4765aab3c3c833d8191e552b5a518fcb6a 100644 (file)
@@ -29,7 +29,7 @@
    Changes: Joseph Wenninger
             Christian Thalinger
 
-   $Id: VMRuntime.c 1465 2004-11-08 11:09:01Z twisti $
+   $Id: VMRuntime.c 1487 2004-11-12 11:25:19Z twisti $
 
 */
 
 #include <dlfcn.h>
 #endif
 
+/* this should work on BSD */
+/*
+#if defined(__DARWIN__)
+#include <sys/sysctl.h>
+#endif
+*/
+
 #undef JOWENN_DEBUG
 
 /* should we run all finalizers on exit? */
 static bool finalizeOnExit = false;
 
-
 /* temporary property structure */
 
 typedef struct property property;
@@ -254,6 +260,33 @@ JNIEXPORT s4 JNICALL Java_java_lang_VMRuntime_availableProcessors(JNIEnv *env, j
 #elif defined(_SC_NPROCESSORS_ONLN)
        return (s4) sysconf(_SC_NPROCESSORS_ONLN);
 
+#elif defined(__DARWIN__)
+       /* this should work in BSD */
+       /*
+       int ncpu, mib[2], rc;
+       size_t len;
+
+       mib[0] = CTL_HW;
+       mib[1] = HW_NCPU;
+       len = sizeof(ncpu);
+       rc = sysctl(mib, 2, &ncpu, &len, NULL, 0);
+
+       return (s4) ncpu;
+       */
+
+       host_basic_info_data_t hinfo;
+       mach_msg_type_number_t hinfo_count = HOST_BASIC_INFO_COUNT;
+       kern_return_t rc;
+
+       rc = host_info(mach_host_self(), HOST_BASIC_INFO,
+                                  (host_info_t) &hinfo, &hinfo_count);
+       if (rc != KERN_SUCCESS) {
+               return -1;
+       }
+
+    return (s4) hinfo.avail_cpus;
+
 #else
        return 1;
 #endif