extern JavaVM* jvm;
int set_thread_priority(int prio) {
int err = 0;
JNIEnv* env;
jclass clz;
jmethodID mid;
jobject thread;
if (!jvm)
return -1;
err = (*jvm)->AttachCurrentThread(jvm, &env, 0);
if (err < 0) {
err = -1;
goto done;
}
clz = (*env)->FindClass(env, "java/lang/Thread");
if (!clz) {
err = -1;
goto done;
}
mid = (*env)->GetStaticMethodID(env, clz, "currentThread",
"()Ljava/lang/Thread;");
if (!mid) {
err = -1;
goto done;
}
thread = (*env)->CallStaticObjectMethod(env, clz, mid);
if (!thread) {
err = -1;
goto done;
}
mid = (*env)->GetMethodID(env, clz, "setPriority", "(I)V");
if (!mid) {
err = -1;
goto done;
}
(*env)->CallVoidMethod(env, thread, mid, prio);
mid = (*env)->GetMethodID(env, clz, "getPriority", "()I");
if (mid) {
prio = (*env)->CallIntMethod(env, thread, mid);
debug("new thread priority is %d\n", prio);
}
done:
(*jvm)->DetachCurrentThread(jvm);
return err;
}
On 11月11日, 午後9:53, Sambhav <[email protected]> wrote:
> Hi,
>
> For thread priorities to be respected in regular linux we use *
> pthread_attr_setinheritsched* API
> pthread_attr_setinheritsched (&tattr, PTHREAD_EXPLICIT_SCHED);
>
> But this is not supported in Android. I have a system which runs real time
> in regular linux and after migrating to Android it does not run real time.
> What is the reason for not supporting this feature and is there any way in
> which this can be enabled ?
> Is there any other way in which thread priority can be reflected in Android
> ?
>
> Regards,
> Sambhav
--
unsubscribe: [email protected]
website: http://groups.google.com/group/android-porting