Patch: sleep(0)

Tom Tromey tromey@cygnus.com
Tue Aug 17 20:47:00 GMT 1999


This patch changes Thread.sleep so that sleep(0) won't sleep forever.
I'm checking this in.

1999-08-17  Tom Tromey  <tromey@cygnus.com>

	* java/lang/natThread.cc (sleep): Turn 0 millis and 0 nanos into 1
	nano.
	* include/quick-threads.h (_Jv_CondWait): Don't round to 0
	inappropriately.

Tom

Index: include/quick-threads.h
===================================================================
RCS file: /cvs/java/libgcj/libjava/include/quick-threads.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 quick-threads.h
--- quick-threads.h	1999/04/07 14:52:35	1.1.1.1
+++ quick-threads.h	1999/08/18 03:12:02
@@ -38,7 +38,11 @@
 _Jv_CondWait (_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *mu,
 	      jlong millis, jint nanos)
 {
-  return coop_condition_variable_wait (cv, mu, millis * 1000 + nanos / 1000);
+  long micros = millis * 1000 + nanos / 1000;
+  // Don't round to 0 inappropriately.
+  if (! micros && (millis || nanos))
+    micros = 1;
+  return coop_condition_variable_wait (cv, mu, micros);
 }
 
 inline int
Index: java/lang/natThread.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/natThread.cc,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 natThread.cc
--- natThread.cc	1999/04/07 14:52:38	1.1.1.1
+++ natThread.cc	1999/08/18 03:12:02
@@ -214,6 +214,9 @@
   if (millis < 0 || nanos < 0 || nanos > 999999)
     _Jv_Throw (new IllegalArgumentException);
 
+  if (millis == 0 && nanos == 0)
+    ++nanos;
+
   Thread *current = currentThread ();
   if (current->isInterrupted ())
     _Jv_Throw (new InterruptedException);


More information about the Java-patches mailing list