* src/classes/gnuclasspath/java/lang/VMThread.java (sleep): Made
authorChristian Thalinger <twisti@complang.tuwien.ac.at>
Sat, 26 Jul 2008 16:58:39 +0000 (18:58 +0200)
committerChristian Thalinger <twisti@complang.tuwien.ac.at>
Sat, 26 Jul 2008 16:58:39 +0000 (18:58 +0200)
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

src/classes/gnuclasspath/java/lang/VMThread.java
src/native/vm/gnuclasspath/java_lang_VMThread.cpp

index a511f3cf05691c657a5f6c92d620df11df3e3bae..e4f2595d323353b90ff6f0220b2f7fe50b896c18 100644 (file)
@@ -376,41 +376,42 @@ final class VMThread
      * @throws InterruptedException if the Thread is (or was) interrupted;
      *         it's <i>interrupted status</i> 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
index ddb9ac1b25476bb6b50e0385d1303d356711ad8c..3b7b07a8fcfb1597a0cdcae0727c37f1f45baed3 100644 (file)
@@ -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          },