From: Christian Thalinger Date: Sat, 26 Jul 2008 16:58:39 +0000 (+0200) Subject: * src/classes/gnuclasspath/java/lang/VMThread.java (sleep): Made X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=e73bfd420e6a6485c394d6f46a3071ca532765e0;p=cacao.git * src/classes/gnuclasspath/java/lang/VMThread.java (sleep): Made native. * src/native/vm/gnuclasspath/java_lang_VMThread.c (sleep): New function. --HG-- extra : transplant_source : %8B%ECj%02%1CKJP%E9%FA%C8%A2%0F%D8%17%13v%94i%14 --- diff --git a/src/classes/gnuclasspath/java/lang/VMThread.java b/src/classes/gnuclasspath/java/lang/VMThread.java index a511f3cf0..e4f2595d3 100644 --- a/src/classes/gnuclasspath/java/lang/VMThread.java +++ b/src/classes/gnuclasspath/java/lang/VMThread.java @@ -376,41 +376,42 @@ final class VMThread * @throws InterruptedException if the Thread is (or was) interrupted; * it's interrupted status will be cleared */ - static void sleep(long ms, int ns) throws InterruptedException - { - // Note: JDK treats a zero length sleep is like Thread.yield(), - // without checking the interrupted status of the thread. - // It's unclear if this is a bug in the implementation or the spec. - // See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6213203 - if (ms == 0 && ns == 0) - { - if (Thread.interrupted()) - throw new InterruptedException(); - return; - } +// static void sleep(long ms, int ns) throws InterruptedException +// { +// // Note: JDK treats a zero length sleep is like Thread.yield(), +// // without checking the interrupted status of the thread. +// // It's unclear if this is a bug in the implementation or the spec. +// // See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6213203 +// if (ms == 0 && ns == 0) +// { +// if (Thread.interrupted()) +// throw new InterruptedException(); +// return; +// } - // Compute end time, but don't overflow - long now = System.currentTimeMillis(); - long end = now + ms; - if (end < now) - end = Long.MAX_VALUE; +// // Compute end time, but don't overflow +// long now = System.currentTimeMillis(); +// long end = now + ms; +// if (end < now) +// end = Long.MAX_VALUE; - // A VM is allowed to return from wait() without notify() having been - // called, so we loop to handle possible spurious wakeups. - VMThread vt = Thread.currentThread().vmThread; - synchronized (vt) - { - while (true) - { - vt.wait(ms, ns); - now = System.currentTimeMillis(); - if (now >= end) - break; - ms = end - now; - ns = 0; - } - } - } +// // A VM is allowed to return from wait() without notify() having been +// // called, so we loop to handle possible spurious wakeups. +// VMThread vt = Thread.currentThread().vmThread; +// synchronized (vt) +// { +// while (true) +// { +// vt.wait(ms, ns); +// now = System.currentTimeMillis(); +// if (now >= end) +// break; +// ms = end - now; +// ns = 0; +// } +// } +// } + static native void sleep(long ms, int ns) throws InterruptedException; /** * Determine whether the current Thread has been interrupted, and clear diff --git a/src/native/vm/gnuclasspath/java_lang_VMThread.cpp b/src/native/vm/gnuclasspath/java_lang_VMThread.cpp index ddb9ac1b2..3b7b07a8f 100644 --- a/src/native/vm/gnuclasspath/java_lang_VMThread.cpp +++ b/src/native/vm/gnuclasspath/java_lang_VMThread.cpp @@ -211,6 +211,19 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_yield(JNIEnv *env, jclass clazz) } +/* + * Class: java/lang/VMThread + * Method: sleep + * Signature: (JI)V + */ +JNIEXPORT void JNICALL Java_java_lang_VMThread_sleep(JNIEnv *env, jclass clazz, int64_t ms, int32_t ns) +{ +#if defined(ENABLE_THREADS) + threads_sleep(ms, ns); +#endif +} + + /* * Class: java/lang/VMThread * Method: interrupted @@ -330,6 +343,7 @@ static JNINativeMethod methods[] = { { (char*) "nativeStop", (char*) "(Ljava/lang/Throwable;)V", (void*) (uintptr_t) &Java_java_lang_VMThread_nativeStop }, { (char*) "currentThread", (char*) "()Ljava/lang/Thread;", (void*) (uintptr_t) &Java_java_lang_VMThread_currentThread }, { (char*) "yield", (char*) "()V", (void*) (uintptr_t) &Java_java_lang_VMThread_yield }, + { (char*) "sleep", (char*) "(JI)V", (void*) (uintptr_t) &Java_java_lang_VMThread_sleep }, { (char*) "interrupted", (char*) "()Z", (void*) (uintptr_t) &Java_java_lang_VMThread_interrupted }, { (char*) "holdsLock", (char*) "(Ljava/lang/Object;)Z", (void*) (uintptr_t) &Java_java_lang_VMThread_holdsLock }, { (char*) "getState", (char*) "()Ljava/lang/String;", (void*) (uintptr_t) &Java_java_lang_VMThread_getState },