Patch: platform usleep function

Ranjit Mathew rmathew@hotmail.com
Fri Dec 20 01:36:00 GMT 2002


Tom Tromey wrote:
> Here is the platform usleep patch.  Ranjit, could you implement
> _Jv_platform_usleep for Win32?  Patch form would be great.  Once I
> have that I'll check it all in.

How does the attached patch look?

Like usleep( ) it has no effect if "usecs" is 0. It provides
a granularity of 1 millisecond and will sleep for *at least*
"usecs" microseconds.

I'm a bit confused about the "wakeability" of a thread in
usleep( ) - some say it is undefined, some say it would be
woken up. If it is "wakeable", I should use the Win32 SleepEx( )
function with "alertable" set to true. See the following for
details:

http://msdn.microsoft.com/library/en-us/dllproc/base/sleepex.asp


ChangeLog:

2002-12-20  Ranjit Mathew  <rmathew@hotmail.com>

	* include/win32.h (_Jv_platform_usleep): New function.

----------------------------- 8< -----------------------------
--- include/win32.h     Fri Dec 20 14:02:49 2002
+++ include/win32.h     Fri Dec 20 14:52:41 2002
@@ -49,4 +49,17 @@
  }

+/* Suspends the execution of the current thread for the specified
+   number of microseconds. Tries to emulate the behaviour of
+   usleep( ) on UNIX and provides a granularity of 1 millisecond. */
+inline void
+_Jv_platform_usleep (unsigned long usecs)
+{
+  if (usecs > 0UL)
+    {
+      unsigned long millis = ((usecs + 999UL) / 1000UL);
+      Sleep (millis);
+    }
+}
+
  #ifndef DISABLE_JAVA_NET

----------------------------- 8< -----------------------------

Sincerely Yours,
Ranjit.

-- 
Ranjit Mathew          Email: rmathew AT hotmail DOT com

Bangalore, INDIA.      Web: http://ranjitmathew.tripod.com/





More information about the Java-patches mailing list