diff options
| author | Mikael Ohlson <mikael.ohlson@stericsson.com> | 2010-03-23 14:06:19 +0100 |
|---|---|---|
| committer | Christian Bejram <christian.bejram@stericsson.com> | 2010-06-15 09:07:42 +0000 |
| commit | 8ea8d24fcad0f0113615ef4dd331e4a127a66436 (patch) | |
| tree | 5dcdb40fb0dc1aab4cdb5d7984af124ac5ec3339 /vm/native/java_lang_Runtime.c | |
| parent | 4e0beaf2dd92c4fee91e9204979a4b5feb2a14ab (diff) | |
| download | android_dalvik-8ea8d24fcad0f0113615ef4dd331e4a127a66436.tar.gz android_dalvik-8ea8d24fcad0f0113615ef4dd331e4a127a66436.tar.bz2 android_dalvik-8ea8d24fcad0f0113615ef4dd331e4a127a66436.zip | |
New implementation for java.lang.Runtime's availableProcessors().
This patch adds a native implementation for availableProcessors(),
replacing the hardcoded "always return 1" implementation.
It uses sysconf(_SC_NPROCESSORS_ONLN) to get the number of online
processors.
Signed-off-by: Christian Bejram <christian.bejram@stericsson.com>
Diffstat (limited to 'vm/native/java_lang_Runtime.c')
| -rw-r--r-- | vm/native/java_lang_Runtime.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/vm/native/java_lang_Runtime.c b/vm/native/java_lang_Runtime.c index 1278f032b..36a11ef02 100644 --- a/vm/native/java_lang_Runtime.c +++ b/vm/native/java_lang_Runtime.c @@ -19,7 +19,8 @@ */ #include "Dalvik.h" #include "native/InternalNativePriv.h" - +#include <unistd.h> +#include <limits.h> /* * public void gc() @@ -106,6 +107,26 @@ static void Dalvik_java_lang_Runtime_runFinalization(const u4* args, } /* + * public int availableProcessors() + * + * Returns the number of online processors, at least one. + * + */ +static void Dalvik_java_lang_Runtime_availableProcessors(const u4* args, + JValue* pResult) +{ + long result = 1; +#ifdef _SC_NPROCESSORS_ONLN + result = sysconf(_SC_NPROCESSORS_ONLN); + if (result > INT_MAX) { + result = INT_MAX; + } else if (result < 1 ) { + result = 1; + } +#endif + RETURN_INT((int)result); +} +/* * public void maxMemory() * * Returns GC heap max memory in bytes. @@ -149,6 +170,8 @@ const DalvikNativeMethod dvm_java_lang_Runtime[] = { Dalvik_java_lang_Runtime_freeMemory }, { "gc", "()V", Dalvik_java_lang_Runtime_gc }, + { "availableProcessors", "()I", + Dalvik_java_lang_Runtime_availableProcessors }, { "maxMemory", "()J", Dalvik_java_lang_Runtime_maxMemory }, { "nativeExit", "(IZ)V", @@ -161,4 +184,3 @@ const DalvikNativeMethod dvm_java_lang_Runtime[] = { Dalvik_java_lang_Runtime_totalMemory }, { NULL, NULL, NULL }, }; - |
