From: twisti Date: Fri, 12 Nov 2004 11:25:19 +0000 (+0000) Subject: Implemented availableProcessors() for darwin. X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=037306455e84e046531a07c53854ff762cfc34b6;p=cacao.git Implemented availableProcessors() for darwin. --- diff --git a/nat/Runtime.c b/nat/Runtime.c index 880dcd95d..d6cbb0d83 100644 --- a/nat/Runtime.c +++ b/nat/Runtime.c @@ -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 $ */ @@ -61,12 +61,18 @@ #include #endif +/* this should work on BSD */ +/* +#if defined(__DARWIN__) +#include +#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 diff --git a/src/native/vm/VMRuntime.c b/src/native/vm/VMRuntime.c index 5eb054350..13df6b476 100644 --- a/src/native/vm/VMRuntime.c +++ b/src/native/vm/VMRuntime.c @@ -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 $ */ @@ -61,12 +61,18 @@ #include #endif +/* this should work on BSD */ +/* +#if defined(__DARWIN__) +#include +#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