From 35a94bdca88f0afa5f6922afbf8d17f5ff908466 Mon Sep 17 00:00:00 2001
From: Tom Tromey <tromey@redhat.com>
Date: Tue, 31 Dec 2002 17:43:47 +0000
Subject: [PATCH] re PR libgcj/8997 (spin() calls Thread.sleep)

2002-12-31  Tom Tromey  <tromey@redhat.com>
            Ranjit Mathew  <rmathew@hotmail.com>

	Fix for PR libgcj/8997:
	* java/lang/natObject.cc (spin): Use _Jv_platform_usleep.
	Include platform.h.
	* include/posix.h (_Jv_platform_usleep): New function.
	* include/win32.h (_Jv_platform_usleep): New function.

Co-Authored-By: Ranjit Mathew <rmathew@hotmail.com>

From-SVN: r60700
---
 libjava/ChangeLog              |  9 +++++++++
 libjava/include/posix.h        |  6 ++++++
 libjava/include/win32.h        | 13 +++++++++++++
 libjava/java/lang/natObject.cc |  6 ++++--
 4 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index ae32ff1e4baa..2644aeedc51e 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,12 @@
+2002-12-31  Tom Tromey  <tromey@redhat.com>
+            Ranjit Mathew  <rmathew@hotmail.com>
+
+	Fix for PR libgcj/8997:
+	* java/lang/natObject.cc (spin): Use _Jv_platform_usleep.
+	Include platform.h.
+	* include/posix.h (_Jv_platform_usleep): New function.
+	* include/win32.h (_Jv_platform_usleep): New function.
+
 2002-12-29  Tom Tromey  <tromey@redhat.com>
 
 	* gcj/javaprims.h: Updated.
diff --git a/libjava/include/posix.h b/libjava/include/posix.h
index cdcdb5d45ac6..859db6e6ba10 100644
--- a/libjava/include/posix.h
+++ b/libjava/include/posix.h
@@ -60,6 +60,12 @@ _Jv_platform_close_on_exec (jint fd)
   ::fcntl (fd, F_SETFD, FD_CLOEXEC);
 }
 
+inline void
+_Jv_platform_usleep (unsigned long usecs)
+{
+  usleep (usecs);
+}
+
 #ifndef DISABLE_JAVA_NET
 
 #ifndef HAVE_SOCKLEN_T
diff --git a/libjava/include/win32.h b/libjava/include/win32.h
index d4c0ab6c18d3..8ba6ef2053c5 100644
--- a/libjava/include/win32.h
+++ b/libjava/include/win32.h
@@ -48,6 +48,19 @@ _Jv_platform_close_on_exec (jint)
   // Ignore.
 }
 
+/* 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
 
 static inline int
diff --git a/libjava/java/lang/natObject.cc b/libjava/java/lang/natObject.cc
index 4c2fd6cab038..a050baa3f669 100644
--- a/libjava/java/lang/natObject.cc
+++ b/libjava/java/lang/natObject.cc
@@ -1,6 +1,6 @@
 // natObject.cc - Implementation of the Object class.
 
-/* Copyright (C) 1998, 1999, 2000, 2001  Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001, 2002  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -28,6 +28,8 @@ details.  */
 #include <java/lang/Cloneable.h>
 #include <java/lang/Thread.h>
 
+#include "platform.h"
+
 #ifdef LOCK_DEBUG
 #  include <stdio.h>
 #endif
@@ -532,7 +534,7 @@ spin(unsigned n)
       unsigned duration = MIN_SLEEP_USECS << (n - yield_limit);
       if (n >= 15 + yield_limit || duration > MAX_SLEEP_USECS)
         duration = MAX_SLEEP_USECS;
-      java::lang::Thread::sleep(0, duration);
+      _Jv_platform_usleep(duration);
     }
 }
 
-- 
GitLab